I have the following dataframe with information from weather stations:
import pandas as pd
import numpy as np
df = pd.DataFrame({'Code Weather Station': ['1024', '1024', '1024', '2089',
'2089', '2089', '8974'],
'Instrumentation': ['Pluviometer-Analog', 'speedometer', 'incidence-sun',
'speedometer', 'Pluviometer', 'speedometer',
'Pluviometer']})
I would like to group the instruments from each of the weather stations.
I tried to use groupby, along with the sum () function, as follows:
df_New = df.groupby('Code Weather Station', as_index=False)['Instrumentation'].sum()
The result is as expected. However, I wish there were spaces among the instruments.
print(df_New)
Code Weather Station Instrumentation
1024 Pluviometer-Analogspeedometerincidence-sun
2089 speedometerPluviometerspeedometer
8974 Pluviometer
I would like the output to be:
Code Weather Station Instrumentation
1024 Pluviometer-Analog speedometer incidence-sun
2089 speedometer Pluviometer speedometer
8974 Pluviometer
Thank you.