Join the Stack Overflow Community
Stack Overflow is a community of 6.7 million programmers, just like you, helping each other.
Join them; it only takes a minute:
Sign up

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.

share|improve this question
up vote 1 down vote accepted

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.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.