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 :: how to print hello in python 
Python :: dict to array of string python 
Python :: how to change web browser in python 
Python :: how to make python open a link 
Python :: pandas subtract integer from column 
Python :: python get time difference in milliseconds 
Python :: django populate choice field from database 
Python :: How to make an simple python client 
Python :: check if coroutine python 
Python :: tkinter clear entry 
Python :: arithmetic python string 
Python :: python read column from csv 
Python :: arabic in python 
Python :: python discord input 
Python :: python ndarray string array into int 
Python :: discord python bot require one of two roles for command 
Python :: hello world flask python 
Python :: can you edit string.punctuation 
Python :: reduce in python 
Python :: corona 
Python :: python time function duration and memory usage 
Python :: check pip installed packages inside virtualenv 
Python :: flask post vs get 
Python :: django print settings 
Python :: A GDAL API version must be specified. Provide a path to gdal-config using a GDAL_CONFIG environment variable or use a GDAL_VERSION environment variable. 
Python :: df.shape 0 
Python :: python writing to csv file 
Python :: python dataframe get numeric columns 
Python :: read csv and set column name in pandas 
Python :: how to iterate pandas dataframe 
ADD CONTENT
Topic
Content
Source link
Name
1+6 =