Форум сайта python.su
Добрый!
У меня возникла такая проблемка:
Есть DF в Pandas, со столбцами: date, city, weather, latitude, longitude
Есть второй DF со столбцами: date, city, code, person
Нужно объединить их по столбцу city и date. Я использую код:
df3 = pd.merge(df1, df2, on =['date','city'], how ='left')
Отредактировано Ken88 (Авг. 7, 2023 15:20:57)
Офлайн
To solve this problem, you can use how='outer'. This option will perform concatenation on outer matches. This means that all rows from both data frames will be included in the results, even if they do not match on all columns.
In your case, this will produce the following output:
2023-06-29 | Moscow | 27 | Leonid
2023-06-30 | Kazan | 28 | Olya
2023-06-30 | Chelny | 31 | Leonid
slope
Офлайн
lilycollins9xthanks
To solve this problem, you can use how='outer'. This option will perform concatenation on outer matches. This means that all rows from both data frames will be included in the results, even if they do not match on all columns.In your case, this will produce the following output:2023-06-29 | Moscow | 27 | Leonid2023-06-30 | Kazan | 28 | Olya2023-06-30 | Chelny | 31 | Leonid connections unlimited
Отредактировано WilliamThompson (Апрель 23, 2024 10:55:41)
Офлайн