麦粉社区
>
帖子详情

python学习篇-pandas库(三)

数据挖掘 发表于 2019-12-13 22:14
发表于 2019-12-13 22:14:56
Series运算
创建原始数据集
  1. import pandas as pd
  2. s3 = pd.Series({'a': 1, 'b': 2, 'c': 3, 'd': 4, 'e': 5} )
  3. s1 = pd.Series([0, 1, 2, 3, 4])
  4. s1.index = ['A', 'B', 'C', 'D', 'E']
  5. s4 = s3.append(s1)
  6. print('数据集s4:\n',s4,'数据集s3:\n',s3)
复制代码
591935df398d850276.png
1、Series减法运算:
Series的减法运算是按照索引计算,如果索引不同则填充为NaN
  1. s4.sub(s3)
复制代码
882745df3999b56d54.png
2、Series加法运算:
Series的加法运算是按照索引计算,如果索引不同则填充为NaN
  1. s4.add(s3)
复制代码
506125df39a276f23f.png
3、Series乘法运算:
Series的乘法运算是按照索引计算,如果索引不同则填充为NaN
  1. s4.mul(s3)
复制代码
614895df39a9c4fa56.png 4、Series除法运算:
Series的除法运算是按照索引计算,如果索引不同则填充为NaN
  1. s4.div(s3)
复制代码
874455df39aea0f6cc.png
5、Series求中位数:
  1. print(s4)
  2. s4.median()
复制代码
705715df39b8b4f146.png
5、Series求和:

  1. print(s4)
  2. s4.sum()
复制代码
849615df39c00ab6d6.png
6、Series求最大值和最小值
  1. print(s4)
  2. max = s4.max()
  3. min = s4.min()
  4. print('max=',max,'\nmin=',min)
复制代码
133395df39caad167e.png
高级模式
B Color Image Link Quote Code Smilies
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

0回帖数 0关注人数 2979浏览人数
最后回复于:2019-12-13 22:14
快速回复 返回顶部 返回列表