赞
踩
目录
实战场景:Pandas如何获取某个数据列最大和最小的5个数
文件读写
数据合并
Pandas
numpy
马上安排!
- iimport numpy as np
- import pandas as pd
-
- np.random.seed(66)
- s1 = pd.Series(np.random.rand(20))
- s2 = pd.Series(np.random.randn(20))
-
- #合并两个Series到DF
- df = pd.concat([s1, s2], axis=1)
- df.columns = ['col1', 'col2']
-
- # 取最大的五个数
-
- print(df["col2"].nlargest(5))
- print()
- # 取最小的五个数
- print(df["col2"].nsmallest(5))

12 1.607623
17 1.404255
19 0.675887
13 0.345030
Name: col2, dtype: float64
16 -1.220877
18 -1.215324
11 -1.003714
8 -0.936607
5 -0.632613
Name: col2, dtype: float64
菜鸟实战,持续学习!
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。