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
.
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.
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.