min and max values for all columns python code example

Example 1: minimum and max value in all columns pandas

#for multiple columns 
min_vals = df[["A","B","C"]].min() #can add how much ever columns
max_vals = df[["D","E","F"]].max() #can add how much ever columns

#for single column
min_val = df["Column"].min() 
max_val = df["Column"].max() 

#to refer to all columns
min_val = df[:].min() 
max_val = df[:].max()

Example 2: python - extract min and max values per each column name

# show me the column names --> predictors
cols = [x for in df.columns if not in ('resp_var', 'name')]; cols


# extract the min and max values per each predictors
print("{")
for i, name in enumerate(cols):
    print(f'"{name}":{{"min":{df[name].min()}, "max":{df[name].max()}}} {"," if i>(len(col)-1) else ""}')
print("}")