<jupyter_start><jupyter_text>Analysis The data set provides a weighting for people (ELE_G_POND_ESC) and trips (ELE_G_POND_ESC2) that allows us to make representative statements on the Madrid population from the sample data. All results take the given weights into account.This is a descriptive analysis on different aspects of gender differences within the mobility data set of Madrid. We look at the following aspects:- distance travelled- trip count- trip motive- modal split- speed- legs- time of day- main activity (occupation) **load data**(for more info on data preprocessing see the  00_setup notebook)<jupyter_code># load data
df = pd.read_csv(r'..\data\processed\trips_custom_variables.csv', dtype = {'VORIHORAINI':str, 'VDESHORAFIN':str}, parse_dates = ['start_time','end_time'])<jupyter_output><empty_output><jupyter_text>distance **weight by ELE_G_POND_ESC2 (weight of trip)**<jupyter_code># weighted average distance by sex
df["weighted_dist"] = df.DISTANCIA_VIAJE * df.ELE_G_POND_ESC2

# get the weighted mean distance
df_sex_sum = df.groupby("sex").sum()
df_sex_sum.weighted_dist / df_sex_sum.ELE_G_POND_ESC2<jupyter_output><empty_output><jupyter_text>Men travel on average 7.8 km, women only 6.4 km.  amount of trips **weighted by ELE_G_POND (weight of individual)**<jupyter_code># weighted average amount or trips by sex
df_ind = df.groupby(["ID_HOGAR", "ID_IND", "sex"]).ELE_G_POND.agg(['mean', 'sum'])
df_ind_sex_sum = df_ind.groupby("sex").sum()
df_ind_sex_sum['sum'] / df_ind_sex_sum['mean']<jupyter_output><empty_output><jupyter_text>Men do on average 2.64 trips per day, women 2.68. Unlike the literature suggests there is no major difference. Do dip deeper, we will look at the average trips by age next:<jupyter_code># weighted average amount or trips by sex

# weighted trip count each individual
trips_by_ind = df.groupby(["ID_HOGAR", "ID_IND", "sex", "rounded_age"]).ELE_G_POND.agg(['mean', 'sum'])

# group by age
trips_by_age = trips_by_ind.reset_index().groupby(["sex", "rounded_age"]).sum().reset_index()
# remove over 90 year olds (too few people)
trips_by_age = trips_by_age[trips_by_age.rounded_age < 90]
# calc weighted trip cound for each age and gender
trips_by_age["weighted_tripcount"] = trips_by_age['sum'] / trips_by_age['mean']

# plot
trips_by_age = trips_by_age.pivot(index='rounded_age', columns='sex', values='weighted_tripcount')
trips_by_age.sort_index().plot(kind = "line", color = ["red", "blue"] )<jupyter_output><empty_output><jupyter_text>Disaggreagted by age we see that women between 25 and 55 do a lot more trips than men. After that it switches and men do more trips. We hypothesize that middle aged women do more trips because they do more care trips especially caring for underaged children. Therefore we'll look at the trip motive next.  trip motive **Average trip count per person by gender and motive**trip motives have been aggregated. Original questionaire was more fine granular.(see 00_setup notebook for details)<jupyter_code>df_ind = df.loc[:,["ID_HOGAR", "ID_IND", "sex", "rounded_age", "ELE_G_POND"]].drop_duplicates()<jupyter_output><empty_output><jupyter_text>**Average amount of trips by age and motive for men**<jupyter_code>sum_people_by_age = df_ind.loc[df.sex == "Man"].groupby(["rounded_age"]).agg({"ELE_G_POND": "sum"}).reset_index()
sum_people_by_age.rename(columns = {'ELE_G_POND': 'people_count'}, inplace = True)

t_age = df.loc[df.sex == "Man"].groupby(["rounded_age", "motive_simple"]).agg({"ELE_G_POND_ESC2": "sum"}).reset_index()
t_age = t_age.join(sum_people_by_age.set_index("rounded_age"), on = "rounded_age")
t_age["trips_by_person"] = t_age.ELE_G_POND_ESC2 / t_age.people_count
# remove over 90 year olds (too few people)
t_age = t_age[t_age.rounded_age < 90]
t_age = t_age.pivot(index='rounded_age', columns='motive_simple', values='trips_by_person')
t_age.sort_index().plot(kind = "line")<jupyter_output><empty_output><jupyter_text>**Average amount of trips by age and motive for women**<jupyter_code>sum_people_by_age = df_ind.loc[df.sex == "Woman"].groupby(["rounded_age"]).agg({"ELE_G_POND": "sum"}).reset_index()
sum_people_by_age.rename(columns = {'ELE_G_POND': 'people_count'}, inplace = True)

t_age = df.loc[df.sex == "Woman"].groupby(["rounded_age", "motive_simple"]).agg({"ELE_G_POND_ESC2": "sum"}).reset_index()
t_age = t_age.join(sum_people_by_age.set_index("rounded_age"), on = "rounded_age")
t_age["trips_by_person"] = t_age.ELE_G_POND_ESC2 / t_age.people_count
t_age = t_age[t_age.rounded_age < 90]
t_age = t_age.pivot(index='rounded_age', columns='motive_simple', values='trips_by_person')
t_age.sort_index().plot(kind = "line")<jupyter_output><empty_output><jupyter_text>As we assumed, middle aged women do more care trips than men. After the age of 55 the care trips increase for men as well as their leisure trips. **weighted percentage of trips purposes**<jupyter_code>sum_of_weighted_trips = pd.DataFrame(df.groupby(["age_group", "sex"]).sum()).reset_index()[["age_group", "sex","ELE_G_POND_ESC2"]]

weighted_trips = df.groupby(["age_group", "sex", "motive_simple"]).sum().reset_index().set_index(["age_group", "sex"])[["motive_simple", "ELE_G_POND_ESC2"]]
weighted_trips = weighted_trips.join(sum_of_weighted_trips.set_index(["age_group", "sex"]), rsuffix = "_total")

weighted_trips["perc"] = weighted_trips.ELE_G_POND_ESC2 / weighted_trips.ELE_G_POND_ESC2_total * 100

weighted_trips.sort_values(["age_group", "sex", "perc"]).head()<jupyter_output><empty_output><jupyter_text>modal split **modal split by aggregated modes**the original questionaire has more fine granular modes. We summarized modes into more generic categories.(see 00_setup notebook for details)<jupyter_code># modal split men weighted
modes_weighted = df[df.sex == 'Man'].groupby(["mode_simple"]).sum()
modes_sex_sum = modes_weighted["ELE_G_POND_ESC2"].sum()
weighted_modes = pd.DataFrame(modes_weighted['ELE_G_POND_ESC2'] / modes_sex_sum).reset_index()
weighted_modes
# modal split women weighted
modes_weighted = df[df.sex == 'Woman'].groupby(["mode_simple"]).sum()
modes_sex_sum = modes_weighted["ELE_G_POND_ESC2"].sum()
weighted_modes = pd.DataFrame(modes_weighted['ELE_G_POND_ESC2'] / modes_sex_sum).reset_index()
weighted_modes<jupyter_output><empty_output><jupyter_text>Men use the car more often (44% vs. women 35%) while women use the public transport (27% vs. 22% men) and walk (36% vs. 31% men) more often than men.   speed speed is computed using the straight-line distance and start and end time of each trip reported by participants.<jupyter_code># weighted average speed by sex
df["weighted_speed"] = df.speed * df.ELE_G_POND_ESC2

# get the weighted mean speed
df_sex_sum = df.groupby("sex").sum()
df_sex_sum.weighted_speed / df_sex_sum.ELE_G_POND_ESC2<jupyter_output><empty_output><jupyter_text>Men are faster on average: 13.6 km/h vs 11.08 km/h.of course the mode plays a major role with speed, so we disaggregate by mode in the next step. **weighted pt speed**only comparing speed of public transport trips<jupyter_code># get the weighted mean speed for public transport
df_pt_sex_sum = df.loc[df.mode_simple == "public transport", ].groupby("sex").sum()
df_pt_sex_sum.weighted_speed / df_pt_sex_sum.ELE_G_POND_ESC2<jupyter_output><empty_output><jupyter_text>**weighted car speed**only comparing speed of trips of cars<jupyter_code># get the weighted mean speed for public transport
df_car_sex_sum = df.loc[df.mode_simple == "car", ].groupby("sex").sum()
df_car_sex_sum.weighted_speed / df_car_sex_sum.ELE_G_POND_ESC2<jupyter_output><empty_output><jupyter_text>**weighted walking speed**only comparing speed of walked trips<jupyter_code># get the weighted mean speed for public transport
df_walk_sex_sum = df.loc[df.mode_simple == "walk", ].groupby("sex").sum()
df_walk_sex_sum.weighted_speed / df_walk_sex_sum.ELE_G_POND_ESC2<jupyter_output><empty_output><jupyter_text>Only walking is the same speed for men and women. By car (21.9 km/h vs. 19.7 km/h) and public transport (12.4 km/h vs. 11.33 km/h) men move faster.Though we need to be careful with this conclusion: as women also do shorter trips on average and longer trips are likely to be faster on average we need to correct for distance. See notebook `02_ModelPTspeed` on this.  legs (etapas) does the trip consist of multiple legs? Especially for public transfers this is interesting, as every leg indicates one transfer.If the public transport network is not accounting as much for female needs as it is for male needs, the amount of transfers is one indicator.<jupyter_code># weighted average legs for public transport

df["weighted_legs"] = df.N_ETAPAS_POR_VIAJE * df.ELE_G_POND_ESC2

df_sex_sum = df.loc[df.mode_simple == "public transport", ].groupby("sex").sum()
df_sex_sum.weighted_legs / df_sex_sum.ELE_G_POND_ESC2<jupyter_output><empty_output><jupyter_text>Both, women and men do 1.62 legs (0.6 transfers) on average.No evidence for a difference here.  main activitymain activities have been aggregated (original questionaire was more fine granular).(see 00_setup notebook for details)<jupyter_code># main activity of indivudals by sex
df.groupby(["sex"]).activity_simple.value_counts(normalize = True)<jupyter_output><empty_output><jupyter_text>time of day At what time of day are trips done by each gender?<jupyter_code>df.loc[df.start_time.notna(), "start_hour"] = df.loc[df.start_time.notna(), "start_time"].apply(lambda x: x.hour)
# weighted count of trips by sex and daytime
g = df.groupby(["sex", "start_hour"]).agg({"ELE_G_POND_ESC2": "sum"}).reset_index()
g_plot = g.pivot(index='start_hour', columns='sex', values='ELE_G_POND_ESC2')
g_plot.plot(kind = "line")<jupyter_output><empty_output><jupyter_text>The peaks for women are not as distinct as they are for men.To identify the origin of the peaks we disaggregate the data by main activity.<jupyter_code># weighted count of trips by main activity
g = df.groupby(["activity_simple", "start_hour"]).agg({"ELE_G_POND_ESC2": "sum"}).reset_index()

g_plot = g.pivot(index='start_hour', columns='activity_simple', values='ELE_G_POND_ESC2')

g_plot.plot(kind = "line")<jupyter_output><empty_output><jupyter_text>gender disaggregated look onto the working people:<jupyter_code># weighted only working by gender
g = df[df.activity_simple == "working"].groupby(["sex", "start_hour"]).agg({"ELE_G_POND_ESC2": "sum"}).reset_index()
g_plot = g.pivot(index='start_hour', columns='sex', values='ELE_G_POND_ESC2')

g_plot.plot(kind = "line", figsize = (10,8), color = ["red", "blue"])<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.12361150669324979, 'fraction_numerical': 0.010253489034463116, 'mean_word_length': 7.0906298003072195, 'pattern_counts': {'":': 7, '<': 76, '<?xml version=': 0, '>': 73, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 1, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '18', 'dir': 'jupyter-structured-clean-dedup', 'id': '419887', 'license': 'MIT', 'n_tokens_mistral': 3887, 'n_tokens_neox': 3620, 'n_words': 943, 'path': 'notebooks/01_descriptive_analysis.ipynb', 'repo_name': 'CorrelAid/gender-equality-and-mobility', 'size': '10533'}