How to Fix Empty DataFrame when Merging Two DataFrames | (Troubleshooting #6)

Опубликовано: 25 Март 2022
на канале: Brandon Jacobson
3,702
44

I've spent the last couple of days trying to merge two #pandas #dataframes using the same inner merge I've done in a previous project. No matter what I tried it wouldn't work and no one responded to my StackOverflow questions. Here's a video on some tips how to fix an empty dataframe when doing an inner merge of two dataframes.

Step 1: Check the datatypes of the column you're trying to join on. So if you're trying to merge df and df1 together and you're using PyCharm, do this: print(df.dtypes) and then print (df1.dtypes) and make sure they are of the same datatype. For example, object and object, int64 and int64, float64, etc.

If they are not the same, make them the same by using .astype(str) or int or float.

Step 2: If you're joining two dataframes on a string and they are both object datatypes, then check to make sure there are no trailing or leading spaces. For example, I had to add .rstrip() to the column I was joining to remove the trailing spaces.

Please like this video if it helped you.


Смотрите видео How to Fix Empty DataFrame when Merging Two DataFrames | (Troubleshooting #6) онлайн, длительностью часов минут секунд в хорошем качестве, которое загружено на канал Brandon Jacobson 25 Март 2022. Делитесь ссылкой на видео в социальных сетях, чтобы ваши подписчики и друзья так же посмотрели это видео. Данный видеоклип посмотрели 3,702 раз и оно понравилось 44 посетителям.