2

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!

7
  • can you show how the output should look like? Commented Apr 19, 2019 at 10:44
  • It should look just like the dataframe, but without the column names 'timestamp' and 'number' on it. Commented Apr 19, 2019 at 10:45
  • I am confused here. Why dont you want the names if you want a dataframe back? can you post the output in the question? Commented Apr 19, 2019 at 10:46
  • I don't want a dataframe. I want a pandas Series, which doesn't have the names of the columns on it. I just edited the question, now you can check how I want the pandas Series to look like :) Commented Apr 19, 2019 at 10:47
  • 2
    Do you mean df.set_index('timestamp')['number'].rename_axis(None) ? Commented Apr 19, 2019 at 10:50

1 Answer 1

3

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
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.