roberthsu2003 / __2024_04_17_mon_wed__

Python與AI人工智慧開發入門
25 stars 4 forks source link

請將lesson17資料夾內的world.csv,選取台灣和日本的資料,並且找出2021-01-01~2021-01-31(2021,1月份的資料)。輸出成csv,xlsx,josn #26

Open roberthsu2003 opened 3 weeks ago

chesterXalan commented 3 weeks ago
import pandas as pd

df = pd.read_csv('world.csv')
df1 = df.reindex(columns=['洲名', '國家', '日期', '總確診數', '新增確診數'])

tw_jp_df = df1.query('國家 in ["台灣", "日本"]')
tw_jp_202101_df = tw_jp_df.query('"2021-01-01" <= 日期 <= "2021-01-31"')

tw_jp_202101_df.to_csv('tw_jp_202101.csv', index=False)
tw_jp_202101_df.to_excel('tw_jp_202101.xlsx', index=False, sheet_name='2021-01')
tw_jp_202101_df.to_json('tw_jp_202101.json', index=False, orient='table', force_ascii=False)
日本 台灣
螢幕擷取畫面 2024-06-17 221057 螢幕擷取畫面 2024-06-17 222702
螢幕擷取畫面 2024-06-17 221448 螢幕擷取畫面 2024-06-17 222723
螢幕擷取畫面 2024-06-17 221939 螢幕擷取畫面 2024-06-17 222002
victor1629 commented 3 weeks ago
import numpy as np
import pandas as pd

df1 = pd.read_csv('world.csv')
df2 = df1.reindex(columns=['洲名','國家','日期','總確診數','新增確診數'])
df3= df2.query ('國家=="台灣" | 國家=="日本"')
t_j_2021_01_df = df3. query('日期>="2021-01-01" and 日期<="2021-01-31"')

t_j_2021_01_df.to_csv('t_j_2021_01.csv',index=False)
t_j_2021_01_df.to_excel('t_j_2021_01.xlsx',index=False,sheet_name='2021_01')
t_j_2021_01_df.to_json('t_j_2021_01.json',orient='table',force_ascii=False)

螢幕擷取畫面 2024-06-18 162435 螢幕擷取畫面 2024-06-18 162448

螢幕擷取畫面 2024-06-18 162721

螢幕擷取畫面 2024-06-18 162800 螢幕擷取畫面 2024-06-18 162819 螢幕擷取畫面 2024-06-18 162831

Tony840705 commented 3 weeks ago
import numpy as np
import pandas as pd

df1 = pd.read_csv('world.csv')
df2 = df1.reindex(columns=['洲名','國家','日期','總確診數','新增確診數'])
df3 = df2.query('日期>="2021-01-01" and 日期<="2021-01-31"and 國家==["台灣","日本"]')

df3.to_csv('TWJP202101.csv',index=False)
df3.to_excel('TWJP202101.xlsx',index=False,sheet_name='2021-01')
df3.to_json('TWJP202101.json',orient='table',force_ascii=False)

HW1

HW2

HW3-1  HW3-2

PercJK commented 3 weeks ago
import numpy as np
import pandas as pd

df1 = pd.read_csv('world.csv')
df2 = df1.reindex(columns=['洲名','國家','日期','總確診數','新增確診數'])
tw_jp_df = df2.query('日期>="2021-01-01" and 日期<="2021-01-31" and 國家==["台灣","日本"]')

tw_jp_df.to_csv('tw_jp_202101.csv',index=False)
tw_jp_df.to_excel('tw_jp_202101.xlsx',index=False,sheet_name='202101')
tw_jp_df.to_json('tw_jp_202101.json',orient='table',force_ascii=False)

lesson17 excel japan lesson17 excel taiwan lesson17 japan csv lesson17 tw csv lesson17 json japan lesson17taiwan json

chiayuben commented 3 weeks ago
import numpy as np
import pandas as pd

df1=pd.read_csv('world.csv')
df2=df1.reindex(columns=['洲名','國家','日期','總確診數','新增確診數','總人口數'])
tw_ja_df3=df2.query('國家=="台灣" or 國家=="日本"')
tw_ja_2021jan_df4=tw_ja_df3.query('日期>="2021-01-01" and 日期<="2021-01-31"')

tw_ja_2021jan_df4.to_csv('tw_ja_2021jan_df4.csv',index=False)
tw_ja_2021jan_df4.to_excel('tw_ja_2021jan_df4.xlsx',index=False)
tw_ja_2021jan_df4.to_json('tw_ja_2021jan_df4.json',orient='table',force_ascii=False)

xlsx: image

csv: image

json: image

Tina54321 commented 3 weeks ago
import pandas as pd

df1 = pd.read_csv('world.csv')
df2 = df1.reindex(columns=['洲名', '國家', '日期', '總確診數', '新增確診數'])
conutry_df = df2.query("國家=='台灣' or 國家=='日本'")
date_df = conutry_df.query('日期>= "2021-01-01" and 日期<= "2021-12-31"')

date_df.to_csv('tw_jp_2021.csv', index=False)
date_df.to_excel('tw_jp_2021.xlsx', index=False, sheet_name='2021')
date_df.to_json('tw_jp_2021.json', orient='table',force_ascii=False)

image image

chihweihan commented 2 weeks ago
import numpy as np
import pandas as pd

df1= pd.read_csv('world.csv')
df2 = df1.reindex(columns=['洲名','國家','日期','總確診數','新增確診數'])
twjp_df = df2.query('國家=="台灣" or 國家=="日本"')
twjp202101_df = twjp_df.query('日期>="2021-01-01" and 日期<="2021-01-31"')

twjp202101_df.to_csv('twjp202101.csv',index=False)
twjp202101_df.to_excel('twjp202101.xlsx',index=False,sheet_name='2021')
twjp202101_df.to_json('twjp202101.json', orient='table', force_ascii=False)

image image image image