查找dataframe的最小值/最大值

方法一:利用DataFrame.min()

用法:DataFrame.min(axis=None, skipna=None, level=None, numeric_only=None, **kwargs)
参数:
axis: Align object with threshold along the given axis.
skipna:Exclude NA/null values when computing the result
level:If the axis is a MultiIndex (hierarchical), count along a particular level, collapsing into a Series
numeric_only:Include only float, int, boolean columns. If None, will attempt to use everything, then use only numeric data. Not implemented for Series.

# importing pandas as pd 
import pandas as pd 
  
# Creating the dataframe  
df = pd.DataFrame({"A":[12, 4, 5, None, 1], 
                   "B":[7, 2, 54, 3, None], 
                   "C":[20, 16, 11, 3, 8],  
                   "D":[14, 3, None, 2, 6]}) 
  
# Print the dataframe 
df

查找dataframe的最小值/最大值_第1张图片

# skip the Na values while finding the minimum 
df.min(axis = 1, skipna = True)

# pick min_value
a,b,c,d,e = df.min(axis = 1, skipna = True)

查找dataframe的最小值/最大值_第2张图片
a:7.0, b=2.0, c=5.0, d=2.0, e=1.0

方法二:DataFrame.values数组 —> array.min

// DataFrame  df 如下:
0	1
0	5.1	3.5
1	4.9	3.0
2	4.7	3.2
3	4.6	3.1
4	5.0	3.6
...	...	...
145	6.7	3.0
146	6.3	2.5
147	6.5	3.0
148	6.2	3.4
149	5.9	3.0
150 rows × 2 columns
// An highlighted block
df.values.min(0) # 等同于 df.values.min(axis=0)
Out[]: array([4.3, 2. ])

你可能感兴趣的:(机器学习,python,pandas,开发语言)