Introduction to Python data analysis (8): Pandas statistical calculation and description

Squirrels love biscuits 2021-04-07 16:28:20
introduction python data analysis pandas


Sample code :

arr1 = np.random.rand(4,3)
pd1 = pd.DataFrame(arr1,columns=list('ABC'),index=list('abcd'))
f = lambda x: '%.2f'% x
pd2 = pd1.applymap(f).astype(float)
pd2

 

Running results :

 A B C
a 0.87 0.26 0.67
b 0.69 0.89 0.17
c 0.94 0.33 0.04
d 0.35 0.46 0.29

 

Common statistical calculation

sum, mean, max, min…

axis=0 Count by column ,axis=1 Count by line

skipna Exclude missing values , The default is True

Sample code :

pd2.sum() # By default, this column is Series Calculation , Sum all rows 
pd2.sum(axis='columns') # Specify the sum of all columns in each row 
pd2.idxmax()# Look at the label index of the maximum value of all rows in each column , We can also go through axis='columns' Find the label index of the maximum value of all columns in each row 

 

Running results :

A 2.85
B 1.94
C 1.17
dtype: float64
a 1.80
b 1.75
c 1.31
d 1.10
dtype: float64
A c
B b
C a
dtype: object

 

Common statistical description

describe Generate multiple statistics

Sample code :

pd2.describe()# View summary 

 

Running results :

 A B C
count 4.000000 4.00000 4.000000
mean 0.712500 0.48500 0.292500
std 0.263613 0.28243 0.271585
min 0.350000 0.26000 0.040000
25% 0.605000 0.31250 0.137500
50% 0.780000 0.39500 0.230000
75% 0.887500 0.56750 0.385000
max 0.940000 0.89000 0.670000
# percentage : Divide by the original amount 
pd2.pct_change() # Look at the percentage change in the row , Specify the same axis='columns' Percentage change from column to column 
 A B C
a NaN NaN NaN
b -0.206897 2.423077 -0.746269
c 0.362319 -0.629213 -0.764706
d -0.627660 0.393939 6.250000

 

Common statistical description methods

版权声明
本文为[Squirrels love biscuits]所创,转载请带上原文链接,感谢
https://pythonmana.com/2021/04/20210407161919430k.html

  1. 用 Python 读写 Excel 表格
  2. Python装饰器高级用法
  3. Reading and writing excel table with Python
  4. Python decorator advanced usage
  5. 从零开始学python | 什么是Python JSON?
  6. Learn Python from scratch | what is Python JSON?
  7. Python with关键字原理详解
  8. Python with keyword principle
  9. python + uiautomator2 实现钉钉工单提交
  10. 一个神级般的 Python 调试神器
  11. Nail work order submission based on Python + uiautomator2
  12. A magic Python debugging artifact
  13. 从零开始学python | 什么是Python JSON?
  14. Learn Python from scratch | what is Python JSON?
  15. 上手Pandas,带你玩转数据(3)-- pandas数据存入文件
  16. Start pandas, take you to play with data (3) -- save pandas data into file
  17. Python能代替shell吗?有什么特点?
  18. Can Python replace shell? What are the features?
  19. Scikit-learn 机器学习库介绍!【Python入门】
  20. Scikit learn machine learning library introduction! [introduction to Python]
  21. 【Python从零到壹】面向对象的封装,继承和多态
  22. Scikit-learn 机器学习库介绍!【Python入门】
  23. Python能代替shell吗?有什么特点?
  24. 【Python从零到壹】Python文件的操作详解
  25. 【Python从零到壹】Python爬虫部分开篇
  26. 【Python从零到壹】学习Python爬虫前,你需要先掌握这些内容
  27. 【Python从零到壹】python爬虫系列-网络请求
  28. Object oriented encapsulation, inheritance and polymorphism
  29. Python经典面试题(附答案)!
  30. Scikit learn machine learning library introduction! [introduction to Python]
  31. 菜谱系统小成阶段,Python Web 领域终于攻占一个小山头
  32. Python Web 菜谱项目再次前进一步,从应用层了解内置用户认证系统
  33. Can Python replace shell? What are the features?
  34. Detailed explanation of Python file operation
  35. Python from zero to one
  36. [Python from zero to one] before learning Python crawler, you need to master these contents
  37. [Python from zero to one] Python crawler series - web request
  38. Python经典面试题(附答案)!
  39. Python classic interview questions (with answers)!
  40. When the recipe system was in its infancy, python web finally took over a small hill
  41. Python web menu project takes another step forward to learn about the built-in user authentication system from the application layer
  42. Python classic interview questions (with answers)!
  43. 【Python从零到壹】Python的循环结构详解
  44. 【Python从零到壹】Python列表详解
  45. 【Python从零到壹】Python的字典详解
  46. 【Python从零到壹】Python的字符串详解
  47. 【Python从零到壹】Python基础之函数的应用
  48. 【Python从零到壹】用Python实现植物大战僵尸里的面向对象
  49. Detailed explanation of Python loop structure
  50. Detailed explanation of Python list
  51. Detailed explanation of Python dictionary
  52. Detailed explanation of Python string
  53. [Python from zero to one] the application of Python basic functions
  54. [Python from zero to one] using Python to realize object-oriented in plant vs. zombie
  55. 用 Python 实现微信版飞机大战
  56. 用 Python 实现***帝国中的数字雨落既视感
  57. 想知道未来孩子长相?Python人脸融合告诉你
  58. 我用 Python 做了一个全球疫情数据大屏
  59. Using Python to realize wechat aircraft war
  60. Using Python to realize the visual sense of digital rain in the Empire of the Communist Party of China