I'm unable to plot csv data using python

Viewed 43
1 Answers

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