简体   繁体   中英

Convert pandas data frame (with multiple columns) to series

I'm trying to convert my dataframe which looks like:

             ds          y
0    1999-01-04   0.000000
1    1999-01-05   1.330603
2    1999-01-06   4.556447
3    1999-01-07   6.823689
4    1999-01-08   8.949833
...         ...        ...
5377 2020-05-18  34.497940

To a series that looks like

1999-01-04   0.000000
1999-01-05   1.330603
1999-01-06   4.556447
1999-01-07   6.823689
1999-01-08   8.949833
...         ...       
2020-05-18  34.497940

I have looked at: Convert pandas data frame to series (and many others) and I still cannot accomplish the task.

Would appreciate any help.

We can do

s=df.set_index('ds').y

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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM