Generation

generate functionFri, 24 Feb 2023

There is a Pandas dataframe: spi_rank country spi_score basic_human_needs foundations_of_wellbeing opportunity basic_nutri_med_care water_sanitation shelter personal_safety access_to_knowledge access_to_communications health_wellness environmental_quality personal_rights personal_freedom inclusiveness access_to_advanced_education 61 62.0 Russia 73.45 83.0 79.4 57.94 95.49 97.04 88.56 50.92 94.34 77.42 64.7 81.16 51.79 70.26 30.31 79.4 Write a function that finds the maximum values of each column and transposes them to rows

def colmax(df): maxvalues = [] for col in df.columns: maxvalues.append(df[col].max()) return pd.DataFrame(maxvalues, index=df.columns).T

Questions about programming?Chat with your personal AI assistant