-1

I'm trying to merge pandas dataframes to effectively add a column with "FIPS Codes" according to the county and state in their respective columns.

I'm using pd.merge to do this and getting NaNs. What am I doing wrong?

According to https://pandas.pydata.org/pandas-docs/stable/merging.html this should work.

merged = pd.merge(sales, fips, how='left', on=['county', 'state'])

Here is the head() of sales: sales.head()

And here is the head() of fips: fips.head()

And this is the merged result (with NaNs in the final fips column): merged.head()

Thanks!

Alicia Garcia-Raboso
  • 13,193
  • 1
  • 43
  • 48
HCV
  • 11
  • 4

1 Answers1

3

Standardise the state names across both dataframes. In sales, the state names are abbreviated, in fips the full name is used.

Dylan Kilkenny
  • 325
  • 4
  • 13