this is my dataframe:-
A B C D
1 23 34 23
3 23 21 4
4 5 6 7
what i want to do is read 0th row and add it into a list like this
[A,B,C,D]
(here this column name can be anything)
I have used
data = pd.read_csv(file_path, nrows=0)
But i am not able to add/store it into list
How to do that?
You can easily do this:
list(data)
but it is more explicit to write like t his:
list(data.columns.values)
Edit: As RafAelC said correctly it is better to use tolist()
like t his:
data.columns.values.tolist()
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.