Home > other >  With the pandas how to extract the data header
With the pandas how to extract the data header

Time:09-25


As example, assume that this is from a. CSV file read data inside, but how to bring out the number of this group of each column items (the content of the red box), the name of the

Thank you, python beginner, rookie, searched a lot can not find the relevant posts, help guide,
Thanks a lot!

CodePudding user response:

Nobody answer? Or question is too simple to disdain to answer?

CodePudding user response:



 import pandas as pd 
Data1=pd. Read_csv (' filename. CSV) # read data
Print (data1. Columns)


The Index ([' col1, col2 '], dtype='object')

CodePudding user response:

refer to the second floor hbu_pig response:


 import pandas as pd 
Data1=pd. Read_csv (' filename. CSV) # read data
Print (data1. Columns)


The Index ([' col1, col2 '], dtype='object')


Well thanks, novice to learn ~ ~ ~ ~

CodePudding user response:

I usually write...
[I for I dataframe] in
Returning to the list so convenient processing next

CodePudding user response:

 
The import CSV
With the open (filename. CSV, 'rb') as f:
Reader=CSV. DictReader (f)
Print reader. Fieldnames

CodePudding user response:

The import pandas as pd
F=open (" 132. CSV ")
Df=pd read_csv (f)
One line below the # command is to check the header
Df. The columns

CodePudding user response:

Can also be read directly specify header

CodePudding user response:

data=https://bbs.csdn.net/topics/pd.read_excel (' permutation and combination. XLSX, sheet_name=0, nrows=1, engine='XLRD')
Print (data. The columns)
If not, then the data. The loc try [1]
  • Related