Python_AI

 1.

%%timeit
import csv
def read_csv(file_name):
    with open(file_name,'r+') as f:
        reader = csv.DictReader(f)
        return list(reader)

data = read_csv('./data/BeijingPM20100101_20151231.csv')
temp_list = [float(item['TEMP']) for item in data if item['TEMP']!='NA']
sum(temp_list)/len(temp_list)

2.

%%timeit
import pandas as pd
df = pd.read_csv('./data/BeijingPM20100101_20151231.csv')
#print(df.head())
df['TEMP'].mean()

 

 

 

 

你可能感兴趣的:(Python)