0

I have created a csv data like:csv image link to csv data: https://1drv.ms/x/s!AiBcPojQRu1SgRw-uiiRIQ0LhXYi?e=uEU9d5

and when I print the csv data it shows like this : printed using pandas code I used

and when I plot the data using matplotlib it shows: error on plotting can anyone help me with this?

5
  • pls show the code plot chart that have error? Commented Sep 10, 2022 at 11:36
  • @bao.le I've attached the image to the post now Commented Sep 10, 2022 at 11:51
  • I'm a little confused as to why you call that CSV; in my browser it looks like a spreadsheet, and when I go to "save as" and choose "download a copy", the server tries to send me an .xlsx file? Commented Sep 12, 2022 at 16:51
  • Also, you should add the code as text into the body of your question; the {} icon can be used to format it as code. Commented Sep 12, 2022 at 16:54
  • yah I convert the xlsx to csv using a online converter. Ill use the '{}' next time onwards. Commented Sep 15, 2022 at 18:17

1 Answer 1

1

First Read csv file with header and here are also sub header so need both headers and delete unwanted unmamed which create onself instead of blank space. and then possible to plotting.

import pandas as pd
import matplotlib.pyplot as plt

#read csv file
covid  = pd.read_csv('D:/kerala.csv',header=[1,2],index_col=[0])
print(covid)

#use Header and Subheader
a = covid.columns.get_level_values(0).to_series()
b = a.mask(a.str.startswith('Unnamed')).ffill().fillna('')
covid.columns = [b, covid.columns.get_level_values(1)]
print (covid)

#plotting
covid.plot()
plt.show()

HOPE IT HELP YOU

Sign up to request clarification or add additional context in comments.

2 Comments

It did worked but is it possible to the output like this?: prnt.sc/SPyJr_t9V4Xd
covid = pd.read_csv('D:/kerala.csv',header=[1,2],index_col=[0]),,,,Just use this statement instead of previous it will work garph with district name.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.