Since one column of my pandas dataframe has nan
value, so when I want to get the max value of that column, it just return error.
>>> df.iloc[:, 1].max()
'error:512'
How can I skip that nan
value and get the max value of that column?
In order to check missing values in Pandas DataFrame, we use a function isnull() and notnull(). Both function help in checking whether a value is NaN or not. These function can also be used in Pandas Series in order to find null values in a series.
median() Method to Find Median Ignoring NaN Values. We use the default value of skipna parameter i.e. skipna=True to find the median of DataFrame along the specified axis by ignoring NaN values. If we set skipna=True , it ignores the NaN in the dataframe.
Pandas DataFrame min() Method The min() method returns a Series with the minimum value of each column. By specifying the column axis ( axis='columns' ), the max() method searches column-wise and returns the minimum value for each row.
You can use the pandas max () function to get the maximum value in a given column, multiple columns, or the entire dataframe. The following is the syntax: # df is a pandas dataframe # max value in a column
Here the pandas min () function is used for finding the minimum value of specified axis. In this example of pandas min () function, we will be using level parameter. Here the minimum value of each level is shown in the output. The max function of pandas helps us in finding the maximum values on specified axis.
Here are 4 ways to check for NaN in Pandas DataFrame: (1) Check for NaN under a single DataFrame column: df ['your column name'].isnull ().values.any () (2) Count the NaN under a single DataFrame column:
Similar to that, we can use the idxmin function to search and find the minimum value in a column: The smallest number in the column x1 is the number 1. The previous example has explained how to get the maxima and minima of a pandas DataFrame column. This example shows how to find the row index positions that correspond to the max and min values.
You can use NumPy
's help with np.nanmax
, np.nanmin
:
In [28]: df
Out[28]:
A B C
0 7 NaN 8
1 3 3 5
2 8 1 7
3 3 0 3
4 8 2 7
In [29]: np.nanmax(df.iloc[:, 1].values)
Out[29]: 3.0
In [30]: np.nanmin(df.iloc[:, 1].values)
Out[30]: 0.0
You can use Series.dropna.
res = df.iloc[:, 1].dropna().max()
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With