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 mean values of each column and transposes them to rows

import pandas as pd df = pd.read_csv('SDG_data.csv') def mean_row(data): df_2 = data[["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"]] mean_df = pd.DataFrame(df_2.mean(axis=0)).T return mean_df

Questions about programming?Chat with your personal AI assistant