Home > Net >  I'm unable to plot csv data using python
I'm unable to plot csv data using python

Time:09-15

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?

CodePudding user response:

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

  • Related