图例与python中的列不匹配

时间:2017-05-16 07:10:44

标签: python pandas legend

我正在尝试使用python绘制excel数据的时间序列图。我的数据如下:

         date   x  y  z  Status Charge
0  1995-02-01   1  0  0     NaN     a1
1  1995-02-02   2  1  1     NaN     a1
2  1995-02-03   3  0  0     NaN     a2
3  1995-02-04   4  0  0     NaN     a3
4  1995-02-05   5  0  0     NaN     a4
5  1995-02-06   6  0  0     NaN     a5
6  1995-02-07   7  0  0     NaN     a6
7  1995-02-08   8  0  0     NaN     a7
8  1995-02-09   9  0  0     NaN     a8
9  1995-02-10  10  0  0     NaN     a9
10 1995-02-11  11  0  0     NaN    a10
11 1995-02-12  12  0  0     NaN    a11
12 1995-02-13  13  0  0     NaN    a12>

首先,我想根据列x拆分数据。其次,我想通过费用列绘制z列。我尝试使用以下代码:

import pandas as pd
df = pd.read_excel('file.xlsx')

import matplotlib.pyplot as plt

for i, group in df.groupby('x'):
    plt.figure()
    grouped=group.groupby(df['Charge'])
    grouped.plot(x='date', y='z', title=str(i),marker='o',linestyle='', legend=True)

但是当我使用它时,传说与'charge'列中的组不匹配。有没有人知道如何解决这个问题?

0 个答案:

没有答案