MODE 众数
mean 均值
median 中位数
standard deviation 标准差
numpy:
import numpy as np array_1 = np.array([[1, 2], [3, 4]], float) array_2 = np.array([[5, 6], [7, 8]], float) print array_1 + array_2 print "" print array_1 - array_2 print "" print array_1 * array_2 array_1 = np.array([1, 2, 3], float) array_2 = np.array([[6], [7], [8]], float) print np.mean(array_1) print np.mean(array_2) print "" print np.dot(array_1, array_2)
np.dot
Pandas:
创建一个Series:
import pandas as pd series = pd.Series([‘Dave‘, ‘Cheng-Han‘, ‘Udacity‘, 42, -1789710578]) print series
cuteness = pd.Series([1, 2, 3, 4, 5], index=[‘Cockroach‘, ‘Fish‘, ‘Mini Pig‘, ‘Puppy‘, ‘Kitten‘]) print cuteness > 3 print "" print cuteness[cuteness > 3]
创建一个数据框,DataFram
data = {‘year‘: [2010, 2011, 2012, 2011, 2012, 2010, 2011, 2012], ‘team‘: [‘Bears‘, ‘Bears‘, ‘Bears‘, ‘Packers‘, ‘Packers‘, ‘Lions‘, ‘Lions‘, ‘Lions‘], ‘wins‘: [11, 8, 10, 15, 11, 6, 10, 4], ‘losses‘: [5, 8, 6, 1, 5, 10, 6, 12]} football = pd.DataFrame(data) print football
print football.dtypes print "" print football.describe() print "" print football.head() print "" print football.tail()
data = {‘year‘: [2010, 2011, 2012, 2011, 2012, 2010, 2011, 2012], ‘team‘: [‘Bears‘, ‘Bears‘, ‘Bears‘, ‘Packers‘, ‘Packers‘, ‘Lions‘, ‘Lions‘, ‘Lions‘], ‘wins‘: [11, 8, 10, 15, 11, 6, 10, 4], ‘losses‘: [5, 8, 6, 1, 5, 10, 6, 12]} football = pd.DataFrame(data) print football[‘year‘] print ‘‘ print football.year # shorthand for football[‘year‘] print ‘‘ print football[[‘year‘, ‘wins‘, ‘losses‘]] #显示year,wins,losses,列 print football.iloc[[0]] #显示第一行 print football[3:5] print football[football.wins > 10] #打印wins大于10的数据 print football[(football.wins > 10) & (football.team == "Packers")]
时间: 2024-12-29 07:10:54