今天是30天程式语言研究的第二十天,由于深度学习老师多让我们上了python的进阶课程里面包括之前没上到的pandas,numpy等功能所以这边打算在把之前没补充到的补充再把笔记补的更完整,由于是老师开的补充课程,这边就不附上网址了。
今天主要是python pandas工具书(II)的部分
笔记:
python pandas工具书(II)
***最主要功能
找最大值
print('Get max of Series:')
print('DataFrame', df['Age'].max())
print('Series:', ages.max())
找各类型数值(中位数,平均值,最小最大......)
print('Basic statistics of the numerical data:')
print('DataFrame:', df['Age'].describe())
print('Series', ages.describe())
取单行
ages = df['Age']
print(type(ages), ages.shape) #age.shape是把ages的形状印出来(3, 1)
print(ages) #title在下面
取多行 (要取某个区间 用loc)
sub = df[['Name', 'Age']] #要写要的栏位名称
print(type(sub), sub.shape)
print(sub) #此时title就会在上面 而不是下面
有条件的取
#(大于35的)
above_35 = df[df['Age'] >= 35]
print(type(above_35), above_35.shape)
print(above_35)
#取年纪是22或58的
age_22_58 = df[df['Age'].isin([22, 58])]
print(type(age_22_58), age_22_58.shape)
print(age_22_58)
#同上换个写法(由逻辑判断式)
age_22_58 = df[(df['Age'] == 22) | (df["Age"] == 58)]
print(type(age_22_58), age_22_58.shape)
print(age_22_58)