Уведомления

Группа в Telegram: @pythonsu

#1 Авг. 7, 2023 15:14:20

Ken88
Зарегистрирован: 2023-08-07
Сообщения: 1
Репутация: +  0  -
Профиль   Отправить e-mail  

ВПР на Python

Добрый!

У меня возникла такая проблемка:
Есть DF в Pandas, со столбцами: date, city, weather, latitude, longitude
Есть второй DF со столбцами: date, city, code, person

Нужно объединить их по столбцу city и date. Я использую код:

 df3 = pd.merge(df1,
 df2,
 on =['date','city'],
 how ='left')

Соединение по времени идёт, также как и город, но, почему-то не на всех строчках.
df3 выдает такой результат:

2023-06-29 | Moscow | 27 | Leonid
2023-06-30 | Kazan | 28 | Olya
2023-06-30 | Chelny | 31 | -

хотя во втором DF, указывается, что в такую дату погоду указывал Leonid. Если несколько записей на одного человек, он не цепляется. Почему?

Отредактировано Ken88 (Авг. 7, 2023 15:20:57)

Офлайн

#2 Дек. 23, 2023 03:42:02

lilycollins9x
Зарегистрирован: 2023-12-23
Сообщения: 4
Репутация: +  0  -
Профиль   Отправить e-mail  

ВПР на Python

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

Офлайн

#3 Апрель 23, 2024 10:53:13

WilliamThompson
Зарегистрирован: 2024-04-23
Сообщения: 2
Репутация: +  0  -
Профиль   Отправить e-mail  

ВПР на Python

lilycollins9x
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
thanks

Отредактировано WilliamThompson (Апрель 23, 2024 10:55:41)

Офлайн

Board footer

Модераторировать

Powered by DjangoBB

Lo-Fi Version