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 :: python remove multiple characters from string 
Python :: Scaling Operation in SkLearn 
Python :: Count NaN values of an DataFrame 
Python :: python calculate angle between two points 
Python :: print pandas version python 
Python :: dataframe pandas to spark 
Python :: second y axis matplotlib 
Python :: python beginner practice problems 
Python :: concatenate directories python 
Python :: plot.barh() group by 
Python :: packing and unpacking in python 
Python :: django permission required 
Python :: python creating a dict from a string 
Python :: if dict.values <= int 
Python :: python convert number in array to integer 
Python :: how to get input from list in python 
Python :: import word_tokenize 
Python :: django template date format yyyy-mm-dd 
Python :: python how to find gcd 
Python :: pandas length of array in column 
Python :: create or update django models 
Python :: define empty numpy array 
Python :: python difflib compare two strings 
Python :: hex to binary python3 
Python :: python color text 
Python :: strings are immutable in python 
Python :: import csv from google drive python 
Python :: python chrome 
Python :: tkinter text blurry 
Python :: if list of columns exist pandas 
ADD CONTENT
Topic
Content
Source link
Name
7+9 =