[英]How to plot a multi-indexed dataframe
I have a dataframe, DF
:我有一个数据框DF
:
Data1 Data2
2022/7/8 3 3
2022/7/7 4 2
2022/7/6 5 1
2022/7/5 6 3
2022/7/4 7 2
Doing the following,执行以下操作,
sns.lineplot(x=DF.index, y=DF["Data1"], ax=Myax)
throws the error:抛出错误:
ValueError: Data must be 1-dimensional ValueError:数据必须是一维的
What am I doing wrong there?我在那里做错了什么?
Below is the requested output:以下是请求的输出:
{('USGG10YR Index', 'PX_LAST'): {datetime.date(2018, 12, 31): 2.6842, datetime.date(2019, 1, 1): 2.6842, datetime.date(2019, 1, 2): 2.6204, datetime.date(2019, 1, 3): 2.5535, datetime.date(2019, 1, 4): 2.6677}, ('GTFRF10YR Corp', 'PX_LAST'): {datetime.date(2018, 12, 31): 0.705, datetime.date(2019, 1, 1): 0.705, datetime.date(2019, 1, 2): 0.648, datetime.date(2019, 1, 3): 0.651, datetime.date(2019, 1, 4): 0.697}, ('GTDEM10YR Corp', 'PX_LAST'): {datetime.date(2018, 12, 31): 0.239, datetime.date(2019, 1, 1): 0.239, datetime.date(2019, 1, 2): 0.164, datetime.date(2019, 1, 3): 0.151, datetime.date(2019, 1, 4): 0.206}, ('GTITLII10Y Govt', 'PX_LAST'): {datetime.date(2018, 12, 31): 1.811, datetime.date(2019, 1, 1): 1.811, datetime.date(2019, 1, 2): 1.782, datetime.date(2019, 1, 3): 1.947, datetime.date(2019, 1, 4): 1.974}}
Your columns are a MultiIndex
, so reference accordingly:您的列是MultiIndex
,因此请相应地参考:
sns.lineplot(
x=TenYearGovYieldHist.index,
y=TenYearGovYieldHistf[('USGG10YR Index', 'PX_LAST')],
ax=Myax
)
Or using droplevel
:或使用droplevel
:
sns.lineplot(
x=TenYearGovYieldHist.index,
y=TenYearGovYieldHist.droplevel(1, axis=1)['USGG10YR Index'],
ax=Myax
)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.