I am using Altair to create visualisations based on a local csv file about WW1 bombing incidents.nI tried to make 2 charts: one shows all incidents in the same month, one shows all incidents in the same year.
The new columns are in int64:
# the head of the dataset
month year
10 1917
10 1917
10 1917
10 1917
10 1917
df_filtered.loc[:, 'month'] = pd.to_datetime(df_filtered['MSNDATE'], format='%M').dt.month.astype(int)
df_filtered.loc[:, 'year'] = pd.to_datetime(df_filtered['MSNDATE'], format='%Y').dt.year.astype(int)
year_selection = alt.selection_point(fields=['year'], nearest=True, on='click')
month_selection = alt.selection_point(fields=['month'], nearest=True, on='click')
# For the same year
same_year_incidents = alt.Chart(df_filtered, title='Incidents in the same year').mark_circle(opacity=op_var).encode(
alt.X('WEAPONWEIGHT', axis=alt.Axis(title='Weapon weight')),
alt.Y('BOMBLOAD', axis=alt.Axis(title='Bombload'), scale=alt.Scale(nice=10, zero=False, padding=1)),
color = attackercolor,
size = alt.value(150),
tooltip = ["COUNTRY", "TGTCOUNTRY", 'MSNDATE:T', 'WEAPONWEIGHT', 'BOMBLOAD']
).transform_filter(
year_selection
).add_params(
op_var, brush
).interactive().properties(height=200, width=650)
# For the same month
same_month_incidents = alt.Chart(df_filtered, title='Incidents in the same month').mark_circle(opacity=op_var).encode(
alt.X('WEAPONWEIGHT', axis=alt.Axis(title='Weapon weight')),
alt.Y('BOMBLOAD', axis=alt.Axis(title='Bombload'), scale=alt.Scale(nice=10, zero=False, padding=1)),
color = attackercolor,
size = alt.value(150),
tooltip = ["COUNTRY", "TGTCOUNTRY", 'MSNDATE:T', 'WEAPONWEIGHT', 'BOMBLOAD']
).transform_filter(
month_selection
).add_params(
op_var, brush
).properties(height=200, width=650)
The charts are shown properly when I run the code block: Charts before selecting any object
However, when I click on an chart object(here the top object on the date 14/9/1918) in the bombing_over_time chart, the 2 new charts do not show any object.

I do not understand why it does not work since the columns used for the year_selection and month_selection are just in the type of int64. How can I fix it? I am new to coding and I have never coded in python before. I appreciate your help.