dataframe = pd.DataFrame(np.random.rand(6,4),columns=list(‘ABCD’))
print(dataframe)
1. 获取dataframe的列名: dataframe.columns
ColNames = dataframe.columns
print(ColNames,type(ColNames)) # 注意ColNames的类型是object
ColNames_List = dataframe.columns.tolist()
print(‘------------------------------------------------------’)
print(ColNames_List,type(ColNames_List))
1.2 获取dataframe的列名: dataframe.columns.values
ColNames = dataframe.columns.values
print(ColNames,type(ColNames)) # 注意ColNames的类型是numpy.ndarray
ColNames_List = dataframe.columns.values.tolist()
print(‘------------------------------------------------------’)
print(ColNames_List,type(ColNames_List))