import pandas as pd
data = {‘name’ : pd.Series([‘Alice’, ‘Bob’, ‘Cathy’, ‘Dany’, ‘Ella’, ‘Ford’, ‘Gary’, ‘Ham’, ‘Ico’, ‘Jack’]),
'Math_A' : pd.Series([1.1, 2.2, 3.3, 4.4, 5, 3.2, 2.4, 1.5, 4.3, 4.5]),
'English_A' : pd.Series([3, 2.6, 2, 1.7, 3, 3.3, 4.4, 5, 3.2, 2.4]),
'Math_B' : pd.Series([1.7, 2.5, 3.6, 2.4, 5, 2.2, 3.3, 4.4, 1.5, 4.3]),
'English_B' : pd.Series([5, 2.6, 2.4, 1.3, 3, 3.6, 2.4, 5, 2.2, 3.1]),
'Project_num' : pd.Series([2, 3, 0, 1, 7, 2, 1, 5, 3, 4]),
'Sex' : pd.Series(['F', 'M', 'M', 'F', 'M', 'F', 'M', 'M', 'F', 'M'])
}
df = pd.DataFrame(data)
print(df)
print(“----------------”)
print(df.median())
print(“----------------”)
print(len(df)) # 不包括表头(列标签)
print(df[‘Sex’].nunique())
print(df[‘Sex’].value_counts())
print(“----------------”)
print(df.describe())
print(“----------------”)
print(df.describe(include=‘all’))
print(“----------------”)
print(df.Math_A.describe())
print(“----------------”)
print(df.Project_num.sum())
print(df.count())
print(df.median())
print(df.quantile([0.25,0.75]))
print(df.max())
print(df.min())
print(df.mean())
print(df.var())
print(df.std())
def double (x):
return x*2
print(df.apply(double))
def double (x):
return x*2