๋ฌธ์
From FranceMarketData.xlsx, plot a bar graph of the three categories: "Connections including Cellular M2M", "Connections excluding Cellular M2M", and Smartphone Connections.
-You can choose to plot them separately or in one plots using subplots.
ํ์ด
1. ํจํค์ง ์ํฌํธ ๋ฐ ๋ฐ์ดํฐ ๋ถ๋ฌ์ค๊ธฐ
import pandas as pd
raw=pd.ExcelFile("FranceMarketData.xlsx")
# ์ํธ1๋ง ์ ์ฅ..!
rw=raw.parse('Sheet1', index_col=None)
rw.info()
rw


* ๋ฌธ์ ์์ ๊ทธ๋ ค์ผํ๋ Bar Graph์ ์ธ๊ฐ์ง ์นดํ ๊ณ ๋ฆฌ๊ฐ ์ด๋ ์์น์ ์๋์ง ํ์ธ
๋ฐ์ดํฐ ํ์ ์ด ๋ชจ๋ object์ธ ๊ฒ์ ํ์ธ..!
์ซ์๋ numeric์ผ๋ก ๋ณํํด์ฃผ์ด์ผํจ!
2. ์ ์ฒ๋ฆฌ
~ํ์์๋ ์ปฌ๋ผ[0], ์ปฌ๋ผ[1] ์ญ์ !~
# column(์ด) drop, axis=1์ ์ด์ ๋งํจ
rw2=rw.drop([rw.columns[0], rw.columns[1]], axis=1)
rw2

~0๋ฒ์งธ ํ์ ์ปฌ๋ผ๋ช ์ผ๋ก ์ค์ ํ๊ณ ํ ์ญ์ ~
# 0๋ฒ์งธ ํ์ ์ปฌ๋ผ๋ช
์ผ๋ก ์ค์
rw3=rw2.rename(columns=rw2.iloc[0])
print(rw3)
# index=0๋ฒ์งธ ํ์ ์ญ์
rw4=rw3.drop(rw3.index[0])
rw4

plotํด์ผํ ์นดํ ๊ณ ๋ฆฌ๊ฐ ์ปฌ๋ผ๋ช ์ผ๋ก ์ ์์นํ ๊ฒ์ ํ์ธํ ์ ์์.
~์ซ์๋ฅผ numeric์ผ๋ก ๋ณํ~
# apply(pd.to_numeric) ์์
์ ํด์ค
rw4[["Connections including Cellular M2M", "Connections excluding Cellular M2M", "Smartphone Connections"]]=rw4[["Connections including Cellular M2M", "Connections excluding Cellular M2M", "Smartphone Connections"]].apply(pd.to_numeric)
~์ ์ฝ๊ฒํ๊ธฐ ์ํด์..์ปฌ๋ผ๋ช ์ ๋ค์ ๊ฐ๋จํ๊ฒ ๋ณ๊ฒฝํ์ต๋๋ค~
# ์ปฌ๋ผ๋ช
์ ์ฌ์ค์ ํด์ค
rw4.columns=["Operator","first","second","third"]
rw4

3. plot
# subplot์ผ๋ก bar์ฐจํธ ๊ทธ๋ฆฌ๊ธฐ
fig,ax = plt.subplots(3,1,figsize=(6,12))
ax[0].bar(rw4['Operator'],rw4['first'],color = 'r')
ax[0].set_title("Connections including Cellular M2M")
ax[1].bar(rw4['Operator'],rw4['second'],color = 'b')
ax[1].set_title("Connections excluding Cellular M2M")
ax[2].bar(rw4['Operator'],rw4['third'],color = 'g')
ax[2].set_title("Smartphone Connections")

'๐ ๋ฐ์ดํฐ ๋ถ์ > 03. Data Visualizaton' ์นดํ ๊ณ ๋ฆฌ์ ๋ค๋ฅธ ๊ธ
[๋ฐ์ดํฐ ์๊ฐํ] ์๊ฐํ ์ค์ต - 4 by 4 scatter plot (0) | 2022.03.05 |
---|---|
[๋ฐ์ดํฐ ์๊ฐํ] ์๊ฐํ ์ค์ต - Scatter plot (0) | 2022.03.02 |
[๋ฐ์ดํฐ ์๊ฐํ] ์๊ฐํ ์ค์ต - Pie chart (0) | 2022.03.01 |
[๋ฐ์ดํฐ ์๊ฐํ] 1. MATPLOTLIB(2) (0) | 2022.03.01 |
[๋ฐ์ดํฐ ์๊ฐํ] 1. MATPLOTLIB(1) (0) | 2022.02.24 |
๋ฌธ์
From FranceMarketData.xlsx, plot a bar graph of the three categories: "Connections including Cellular M2M", "Connections excluding Cellular M2M", and Smartphone Connections.
-You can choose to plot them separately or in one plots using subplots.
ํ์ด
1. ํจํค์ง ์ํฌํธ ๋ฐ ๋ฐ์ดํฐ ๋ถ๋ฌ์ค๊ธฐ
import pandas as pd
raw=pd.ExcelFile("FranceMarketData.xlsx")
# ์ํธ1๋ง ์ ์ฅ..!
rw=raw.parse('Sheet1', index_col=None)
rw.info()
rw


* ๋ฌธ์ ์์ ๊ทธ๋ ค์ผํ๋ Bar Graph์ ์ธ๊ฐ์ง ์นดํ ๊ณ ๋ฆฌ๊ฐ ์ด๋ ์์น์ ์๋์ง ํ์ธ
๋ฐ์ดํฐ ํ์ ์ด ๋ชจ๋ object์ธ ๊ฒ์ ํ์ธ..!
์ซ์๋ numeric์ผ๋ก ๋ณํํด์ฃผ์ด์ผํจ!
2. ์ ์ฒ๋ฆฌ
~ํ์์๋ ์ปฌ๋ผ[0], ์ปฌ๋ผ[1] ์ญ์ !~
# column(์ด) drop, axis=1์ ์ด์ ๋งํจ
rw2=rw.drop([rw.columns[0], rw.columns[1]], axis=1)
rw2

~0๋ฒ์งธ ํ์ ์ปฌ๋ผ๋ช ์ผ๋ก ์ค์ ํ๊ณ ํ ์ญ์ ~
# 0๋ฒ์งธ ํ์ ์ปฌ๋ผ๋ช
์ผ๋ก ์ค์
rw3=rw2.rename(columns=rw2.iloc[0])
print(rw3)
# index=0๋ฒ์งธ ํ์ ์ญ์
rw4=rw3.drop(rw3.index[0])
rw4

plotํด์ผํ ์นดํ ๊ณ ๋ฆฌ๊ฐ ์ปฌ๋ผ๋ช ์ผ๋ก ์ ์์นํ ๊ฒ์ ํ์ธํ ์ ์์.
~์ซ์๋ฅผ numeric์ผ๋ก ๋ณํ~
# apply(pd.to_numeric) ์์
์ ํด์ค
rw4[["Connections including Cellular M2M", "Connections excluding Cellular M2M", "Smartphone Connections"]]=rw4[["Connections including Cellular M2M", "Connections excluding Cellular M2M", "Smartphone Connections"]].apply(pd.to_numeric)
~์ ์ฝ๊ฒํ๊ธฐ ์ํด์..์ปฌ๋ผ๋ช ์ ๋ค์ ๊ฐ๋จํ๊ฒ ๋ณ๊ฒฝํ์ต๋๋ค~
# ์ปฌ๋ผ๋ช
์ ์ฌ์ค์ ํด์ค
rw4.columns=["Operator","first","second","third"]
rw4

3. plot
# subplot์ผ๋ก bar์ฐจํธ ๊ทธ๋ฆฌ๊ธฐ
fig,ax = plt.subplots(3,1,figsize=(6,12))
ax[0].bar(rw4['Operator'],rw4['first'],color = 'r')
ax[0].set_title("Connections including Cellular M2M")
ax[1].bar(rw4['Operator'],rw4['second'],color = 'b')
ax[1].set_title("Connections excluding Cellular M2M")
ax[2].bar(rw4['Operator'],rw4['third'],color = 'g')
ax[2].set_title("Smartphone Connections")

'๐ ๋ฐ์ดํฐ ๋ถ์ > 03. Data Visualizaton' ์นดํ ๊ณ ๋ฆฌ์ ๋ค๋ฅธ ๊ธ
[๋ฐ์ดํฐ ์๊ฐํ] ์๊ฐํ ์ค์ต - 4 by 4 scatter plot (0) | 2022.03.05 |
---|---|
[๋ฐ์ดํฐ ์๊ฐํ] ์๊ฐํ ์ค์ต - Scatter plot (0) | 2022.03.02 |
[๋ฐ์ดํฐ ์๊ฐํ] ์๊ฐํ ์ค์ต - Pie chart (0) | 2022.03.01 |
[๋ฐ์ดํฐ ์๊ฐํ] 1. MATPLOTLIB(2) (0) | 2022.03.01 |
[๋ฐ์ดํฐ ์๊ฐํ] 1. MATPLOTLIB(1) (0) | 2022.02.24 |