How to min/max value in multiple columns of a pandas dataframe?

Peter

how can i get one min/max value of several columns from a dataframe? I could not find a simple way to get these values, only with looping over the columns or converting the dataframe multiple times. I think there must be a better way to solve this.

For example, here are some code...

import pandas as pd

df = pd.DataFrame([[0,1,2,3],
                  [6,5,None,pd.NaT],
                  [8,None,9,None],
                  [None,12,7,14]], columns=list('ABCD'))

... this is what's the dataframe looks like and I want the min/max of column 'C' and 'D'.

     A     B    C     D
0  0.0   1.0  2.0     3
1  6.0   5.0  NaN   NaT
2  8.0   NaN  9.0  None
3  NaN  12.0  7.0    14

What is a good way to do this?

Additional Note: The result of both columns ['C','D'] should be one value for min (2) and one value for max (14)

Scott Boston

You can use,

df[['C','D']].min().min()
2.0

and

df[['C', 'D']].max().max()
14.0

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

How to get value counts for multiple columns at once in Pandas DataFrame?

From Dev

How to summarize a pandas DataFrame by group with value counts of multiple columns?

From Dev

Unstacking DataFrame with Multiple 'Value' Columns in Python Pandas

From Dev

How to split a pandas dataframe into multiple columns

From Dev

How to unpack the columns of a pandas DataFrame to multiple variables

From Dev

Pandas dataframe: how to summarize columns containing value

From Dev

Pandas DataFrame.groupby() to dictionary with multiple columns for value

From Dev

How to apply multiple custom functions on multiple columns in grouped DataFrame in pandas?

From Dev

transpose multiple columns Pandas dataframe

From Java

Selecting multiple columns in a pandas dataframe

From Dev

Transposing a pandas dataframe with multiple columns

From Dev

Pandas Dataframe Groupby multiple columns

From Java

How to add multiple columns to pandas dataframe in one assignment?

From Java

How to concat multiple Pandas DataFrame columns with different token separator?

From Dev

How to split a dataframe column into multiple columns with a Pandas converter

From Dev

How to filter pandas dataframe on multiple columns based on a dictionary?

From Dev

How to add multiple columns to pandas dataframe in one assignment?

From Dev

How to concat multiple Pandas DataFrame columns with different token separator?

From Dev

How can I add multiple variable arrays to columns in a pandas dataframe?

From Dev

How to get percentage count based on multiple columns in pandas dataframe?

From Java

How to find which columns contain any NaN value in Pandas dataframe

From Dev

How to replace all value in all columns in a Pandas dataframe with condition

From Dev

pandas dataframe how to sum all value of bigger columns per row

From Dev

How can I sort datetime columns by row value in a Pandas dataframe?

From Java

How to check column value in multiple columns in two dataframes (Pandas)?

From Dev

How to groupby multiple columns with count unique value in Python Pandas

From Dev

Pandas replace the value of multiple columns based on value

From Dev

How to concat Pandas dataframe columns

From Dev

How to reduce columns in dataframe pandas

Related Related

  1. 1

    How to get value counts for multiple columns at once in Pandas DataFrame?

  2. 2

    How to summarize a pandas DataFrame by group with value counts of multiple columns?

  3. 3

    Unstacking DataFrame with Multiple 'Value' Columns in Python Pandas

  4. 4

    How to split a pandas dataframe into multiple columns

  5. 5

    How to unpack the columns of a pandas DataFrame to multiple variables

  6. 6

    Pandas dataframe: how to summarize columns containing value

  7. 7

    Pandas DataFrame.groupby() to dictionary with multiple columns for value

  8. 8

    How to apply multiple custom functions on multiple columns in grouped DataFrame in pandas?

  9. 9

    transpose multiple columns Pandas dataframe

  10. 10

    Selecting multiple columns in a pandas dataframe

  11. 11

    Transposing a pandas dataframe with multiple columns

  12. 12

    Pandas Dataframe Groupby multiple columns

  13. 13

    How to add multiple columns to pandas dataframe in one assignment?

  14. 14

    How to concat multiple Pandas DataFrame columns with different token separator?

  15. 15

    How to split a dataframe column into multiple columns with a Pandas converter

  16. 16

    How to filter pandas dataframe on multiple columns based on a dictionary?

  17. 17

    How to add multiple columns to pandas dataframe in one assignment?

  18. 18

    How to concat multiple Pandas DataFrame columns with different token separator?

  19. 19

    How can I add multiple variable arrays to columns in a pandas dataframe?

  20. 20

    How to get percentage count based on multiple columns in pandas dataframe?

  21. 21

    How to find which columns contain any NaN value in Pandas dataframe

  22. 22

    How to replace all value in all columns in a Pandas dataframe with condition

  23. 23

    pandas dataframe how to sum all value of bigger columns per row

  24. 24

    How can I sort datetime columns by row value in a Pandas dataframe?

  25. 25

    How to check column value in multiple columns in two dataframes (Pandas)?

  26. 26

    How to groupby multiple columns with count unique value in Python Pandas

  27. 27

    Pandas replace the value of multiple columns based on value

  28. 28

    How to concat Pandas dataframe columns

  29. 29

    How to reduce columns in dataframe pandas

HotTag

Archive