如何使用csv进行平均i npython

如何使用csv进行平均i npython,python,Python,使用这些数据,我如何计算整个时期内所有国家的日平均值?假设您将其保存在CSV文件中,使用pandas库非常简单: Date,Indonesia,Japan,Malaysia,Singapore,South Korea,Thailand 15-Apr-20,282,455,170,334,27,30 16-Apr-20,297,482,85,447,22,29 17-Apr-20,380,585,110,728,22,28 18-Apr-20,407,628,69,623,18,33 19-Apr

使用这些数据,我如何计算整个时期内所有国家的日平均值?

假设您将其保存在CSV文件中,使用
pandas
库非常简单:

Date,Indonesia,Japan,Malaysia,Singapore,South Korea,Thailand
15-Apr-20,282,455,170,334,27,30
16-Apr-20,297,482,85,447,22,29
17-Apr-20,380,585,110,728,22,28
18-Apr-20,407,628,69,623,18,33
19-Apr-20,325,566,54,942,8,32
20-Apr-20,327,390,84,596,13,27
21-Apr-20,185,367,36,1426,9,19
22-Apr-20,375,378,57,1111,11,15
23-Apr-20,283,276,50,1016,8,13
24-Apr-20,357,468,71,1037,6,68
25-Apr-20,436,652,88,618,10,0
26-Apr-20,396,290,51,931,10,15
27-Apr-20,275,203,38,799,10,9
28-Apr-20,214,191,40,528,14,7
29-Apr-20,415,276,31,690,9,9
30-Apr-20,260,236,94,528,4,7

也许可以告诉我们你试过什么?我用if elif else来做itef dispAve():ave_data1=ave_data2=ave_data3=ave_data4=ave_data5=ave_data6=total=0 print('='*40)print('Please choose:')print('A-印度尼西亚')print('B-日本')print('C-马来西亚')print('D-新加坡')print('E-韩国'))print('F-Thailand')print('Q-Quit')print('='*40)sel=(input('Please input ur selection:'))如果sel in[“A”,“A”]:total=total+(len(印尼))ave_data1=total/len(印尼)print('印尼的平均每日数据为{ave_data1})类似于帮助mei的TQ可以在def函数中使用它??是的,你可以将它放在函数中。你可以将panda视为excel类型,其中有列和行。检查此链接
import pandas as pd
df = pd.read_csv("file.csv")
print(df.mean())

Indonesia      325.8750
Japan          402.6875
Malaysia        70.5000
Singapore      772.1250
South Korea     12.5625
Thailand        21.3125
dtype: float64