herrDeng網內搜尋

自訂搜尋

Ads

2021年5月10日 星期一

python pandas看covid-19 CSV資訊與必要數據轉換(字幕版)


幾個比較重要的指令
  1. import pandas as pd
  2. import matplotlib.pyplot as plt
  3. df=pd.read_csv('https://od.cdc.gov.tw/eic/covid19/covid19_global_cases_and_deaths.csv')
看看DataFrame df相關的資訊
  1. df.index
  2. df.columns
  3. pd.DataFrame(df, index=[0,1, 7,2,176])
如果要看台灣的資訊
  1. s=df[df['country_en']=='Taiwan']
  2. s
因為資料string必須去掉','並轉換為數字,python的一般作法就是用lambda函數
  1. df0=df.apply(lambda x: x.str.replace(',','').apply(pd.to_numeric, errors='ignore'))
有關死亡人數的資料
  1. df[df0['deaths']>=10000]
  2. deaths=df0['deaths']
  3. print(deaths.describe())
  4. plt.plot(deaths.to_numpy())
  5. plt.show()

沒有留言:

Related Posts Plugin for WordPress, Blogger...

熱門文章