0

I have a multi-index pandas DataFrame with the following structure that I got from a groupby operation:

                   count
year  month  day
2010  1      1       1
             2       3
             3       6
             4      24
             5      31

This continues for many days, months, and years. The DataFrame has three indices (year, month, and day).

What I'd like to do is use matplotlib to plot the count as a function of the date. There are several examples online of plotting dates in matplotlib, so really what I need to do is:

Question:

1) How can I build a separate array or DataFrame that is two columns, first column being the date and second column being the count?

What I tried

for idx, val in enumerate(df3.body):
    print val

That only prints the values of count row by row, but I'm not sure how to access the date.

1 Answer 1

3

I was able to figure it out. I was actually pretty close in what I tried.

for idx, val in enumerate(df.count):
    print val

    # Get the index of this row
    d = df.iloc[idx].name

I didn't realize the .name held the index of the DataFrame. Problem Solved.

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.