Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Seaborn can't do a simple lineplot : ValueError: Data must be 1-dimensional

I have a dataframe 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)

throw the error :

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

ValueError: Data must be 1-dimensional

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

>Solution :

Your columns are a MultiIndex, so reference accordingly:

sns.lineplot(
    x=TenYearGovYieldHist.index, 
    y=TenYearGovYieldHistf[('USGG10YR Index', 'PX_LAST')], 
    ax=Myax
)

Or using droplevel:

sns.lineplot(
    x=TenYearGovYieldHist.index, 
    y=TenYearGovYieldHist.droplevel(1, axis=1)['USGG10YR Index'],
    ax=Myax
)
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading