天天看點

python pandas dataframe函數_Python Pandas dataframe.min()用法及代碼示例

Python是進行資料分析的一種出色語言,主要是因為以資料為中心的python軟體包具有奇妙的生态系統。 Pandas是其中的一種,使導入和分析資料更加容易。

Pandas dataframe.min()函數傳回給定對象中的最小值。如果輸入是一個序列,則該方法将傳回一個标量,該數量将是該序列中的最小值。如果輸入是一個 DataFrame ,則該方法将傳回一個在 DataFrame 的指定軸上具有最小值的序列。預設情況下,該軸是索引軸。

用法: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.

傳回值:min:Series或DataFrame(如果指定級别)

範例1:采用min()函數在索引軸上查找最小值。

# importing pandas as pd

import pandas as pd

# Creating the dataframe

df = pd.DataFrame({"A":[12, 4, 5, 44, 1],

"B":[5, 2, 54, 3, 2],

"C":[20, 16, 7, 3, 8],

"D":[14, 3, 17, 2, 6]})

# Print the dataframe

df

python pandas dataframe函數_Python Pandas dataframe.min()用法及代碼示例

讓我們使用dataframe.min()查找索引軸上的最小值的功能

# find min Even if we do not specify axis = 0, the method

# will return the min over the index axis by default

df.min(axis = 0)

輸出:

python pandas dataframe函數_Python Pandas dataframe.min()用法及代碼示例

範例2:采用min()在具有Na值。還要找到縱軸上的最小值。

# 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

python pandas dataframe函數_Python Pandas dataframe.min()用法及代碼示例

讓我們實作min函數。

# skip the Na values while finding the minimum

df.min(axis = 1, skipna = True)

輸出:

python pandas dataframe函數_Python Pandas dataframe.min()用法及代碼示例