Sunday, September 8, 2024
Homepandaspandas get column names

pandas get column names

dataframe = pd.DataFrame(np.random.rand(6,4),columns=list(‘ABCD’))  
print(dataframe)

1. Get the column names of dataframe: dataframe.columns

ColNames = dataframe.columns  
print(ColNames,type(ColNames)) # NoticeColNamesThe type isobject  
ColNames\_List = dataframe.columns.tolist()  
print(‘------------------------------------------------------’)  
print(ColNames\_List,type(ColNames\_List))

1.2 Get the column names of dataframe: dataframe.columns.values

ColNames = dataframe.columns.values  
print(ColNames,type(ColNames)) # NoticeColNamesThe type isnumpy.ndarray  
ColNames\_List = dataframe.columns.values.tolist()  
print(‘------------------------------------------------------’)  
print(ColNames\_List,type(ColNames\_List))
RELATED ARTICLES

Most Popular

Recent Comments