0

I am trying to join two dataframe one is data for choropleth with postcode and some other value in it another one is postcode and price.

I am trying to join both of them according to correspond postcode in map_df.

After I joined them, the prices are gone and all become NaN. How can I fix this?

enter image description here

Diziet Asahi
  • 38,379
  • 7
  • 60
  • 75
  • 1
    Please see [how to make good reproducible pandas examples](https://stackoverflow.com/questions/20109391/how-to-make-good-reproducible-pandas-examples). Screenshots of data and/or code are discouraged here. – BigBen Oct 19 '20 at 14:47
  • Mostly there are no prices for the records where `NaN` shows up, i.e. there are some postcodes available in `map_df` but not in `df`. Have you checked that? also you should use `merge` not `join` – Rafs Oct 19 '20 at 15:08

2 Answers2

0

You should check merge documentation. I assume you want to do a inner join on post_code.

map_df.merge(df,how="inner",on=["post_code"])
Maxime D.
  • 306
  • 5
  • 17
  • This wouldn't do before renaming the merge column to `post_code` in both of `map_df` and `df` – Rafs Oct 19 '20 at 15:09
0

I solved the problem by changing the type of data in my map_df dataframe. I changed the postcode column from "object" to "int64".