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 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 :: python switch item 
Python :: compare two data frames in assert 
Python :: how to divide string in python 
Python :: convert to string in python 
Python :: python resample and interpolate 
Python :: python logging repeated messages 
Python :: check if binary tree is balanced python 
Python :: Finding Maximum Elements along columns using Python numpy.argmax() 
Python :: python c like struct 
Python :: label with list comprehension python 
Python :: seaborn set figure size 
Python :: selenium options python path 
Python :: how to use custom activity in discord.py 
Python :: centos install python 3.9 thelinuxterminal.com 
Python :: states and capitals us comma separated list 
Python :: random forest classifier classification report 
Python :: Pivot Spark data frame using python 
Python :: python generator function 
Python :: how to set propee timeline in python 
Python :: Setting spacing (minor) between ticks in matplotlib 
Python :: que es una funcion en python 
Python :: os module 
Python :: register models in admin 
Python :: Swap 2 items of a list in python 
Python :: column of lists pandas 
Python :: Common Python String Methods 
Python :: pubg python 
Python :: Python DateTime Time Class Example 
Python :: python replace negative infinity 
Python :: python lambda function use global variable 
ADD CONTENT
Topic
Content
Source link
Name
6+5 =