FB Style Menu

Thursday, February 24, 2022

Data Virtualization by Python - Bar Chart Simple

# Importing pandas and matplotlib

import pandas as pd

import numpy as np

from  matplotlib import pyplot as plt 


# Importing excel table

Mydata = pd.read_excel('D:\\file path\\file name .xlsx')

Mydata








# Note : Python adding it's own index automatically when we read excel. (red circle highlighted)


# Creating simple bar graph

# plt.bar(Mydata ['column name for x axis '],height=Mydata7[ 'column name for y bar'])

plt.bar ( Mydata7 ['City Population'] ,  height = Mydata7 [2019] )


# If we set 'City Population' as index column

Mydata = Mydata.set_index('City Population')

Mydata










# Then, instead of writing 'column name for x axis' , we can use '.index' as x asix

plt.bar (Mydata.index ,  height = Mydata [2019] , color = 'green' )










Source Table

City Population

2019

2020

2021

Yangon

300,000

312,000

350,000

Mandalay

270,000

290,000

310,000

Sagaing

160,000

170,000

190,000

MonYwar

180,000

190,000

210,000

Harkhar

90,000

100,000

110,000

Loikaw

140,000

150,000

160,000



By NwayNz


No comments:

Post a Comment