问题
I need some help with a data types issue. I'm trying to convert a pandas dataframe, which looks like the following:
timestamp number
2018-01-01 1
2018-02-01 0
2018-03-01 5
2018-04-01 0
2018-05-01 6
into a pandas series, which looks exactly like the dataframe, without the column names timestamp and number:
2018-01-01 1
2018-02-01 0
2018-03-01 5
2018-04-01 0
2018-05-01 6
It shouldn't be difficult, but I'm having a little trouble figuring out the way to do it, as I'm a beginner in pandas.
It would be great to get some help with this issue.
Thank you very much in advance!
回答1:
IIUC, use:
df.set_index('timestamp')['number'].rename_axis(None)
2018-01-01 1
2018-02-01 0
2018-03-01 5
2018-04-01 0
2018-05-01 6
来源:https://stackoverflow.com/questions/55760594/converting-pandas-dataframe-to-pandas-series