Search
 
SCRIPT & CODE EXAMPLE
 

PYTHON

pandas dataframe get number of columns

import pandas as pd
df = pd.DataFrame({"pear": [1,2,3], "apple": [2,3,4], "orange": [3,4,5]})

len(df.columns)
3
Comment

get column number in dataframe pandas

# PANDAS: get column number from colomn name
dataframe.columns.get_loc("<col_name>")
Comment

pandas number of columns

### first method ###
len(df.columns)
### second method ###
df.shape[1]
Comment

number of column in dataset pandas

len(df.columns)
Comment

how to count number of columns in dataframe python

import pandas as pd
df = pd.DataFrame({"pear": [1,2,3], "apple": [2,3,4], "orange": [3,4,5]})

len(df.columns)
Comment

how to know the column number of a dataframe in pandas

In [45]: df = DataFrame({"pear": [1,2,3], "apple": [2,3,4], "orange": [3,4,5]})

In [46]: df.columns
Out[46]: Index([apple, orange, pear], dtype=object)

In [47]: df.columns.get_loc("pear")
Out[47]: 2
Comment

pandas df number of columns

df.shape[1]
Comment

PREVIOUS NEXT
Code Example
Python :: else if 
Python :: python turtle tutorial 
Python :: django 3.2 compatible to python 3.10? 
Python :: os.path.join 
Python :: bitbucket rest api python example 
Python :: for schleife python 
Python :: convert date to string in python 
Python :: test pypi 
Python :: python test framework 
Python :: run python file from cmd 
Python :: python module search 
Python :: pyautogui 
Python :: pandas dummy classification data 
Python :: python merge list no duplicates 
Python :: django for beginners 
Python :: python using set 
Python :: get user api 
Python :: python array of objects 
Python :: add an item to a dictionary python 
Python :: if queryset is empty django 
Python :: dot product of lists python 
Python :: hash table python 
Python :: python how to check if string is empty 
Python :: image to vector conversion function 
Python :: python how to loop 
Python :: spreadsheet worksheet counter 
Python :: locate certificate path python 
Python :: django snippet 800 
Python :: python script to execute shell azure cli commands in python 
Python :: function palindrome python 
ADD CONTENT
Topic
Content
Source link
Name
5+9 =