0

I apologise if this has already been asked, I have searched for a solution and found similar problems but non that have solved my problem.

I have 2 DataFrames

df2.head()   

                    Location        lat         lon
0          Albury, Australia -36.080477  146.916280
1  Badgerys Creek, Australia -33.881667  150.744163
2           Cobar, Australia -31.498333  145.834444
3   Coffs Harbour, Australia -30.296241  153.113529
4           Moree, Australia -29.461720  149.840715


df2.shape
(49, 3)

and

df1.info()

RangeIndex: 145460 entries, 0 to 145459
Data columns (total 21 columns):
 #   Column         Non-Null Count   Dtype  
---  ------         --------------   -----  
 0   Date           145460 non-null  object 
 1   Location       145460 non-null  object 
 2   MinTemp        143975 non-null  float64
 3   MaxTemp        144199 non-null  float64
 4   Rainfall       142199 non-null  float64
 5   WindGustDir    135134 non-null  object 
 6   WindGustSpeed  135197 non-null  float64
 7   WindDir9am     134894 non-null  object 
 8   WindDir3pm     141232 non-null  object 
 9   WindSpeed9am   143693 non-null  float64
 10  WindSpeed3pm   142398 non-null  float64
 11  Humidity9am    142806 non-null  float64
 12  Humidity3pm    140953 non-null  float64
 13  Pressure9am    130395 non-null  float64
 14  Pressure3pm    130432 non-null  float64
 15  Temp9am        143693 non-null  float64
 16  Temp3pm        141851 non-null  float64
 17  RainToday      142199 non-null  object 
 18  RainTomorrow   142193 non-null  object 
 19  Country        145460 non-null  object 
 20  ApLocation     145460 non-null  object 
dtypes: float64(12), object(9)

df1 has 49 unique values for location, df2 has those locations with the corresponding longitude and latitude values.

I'd like to map the longitude and latitude values to the corresponding locations in df1.

8TrackRobot
  • 105
  • 2
  • 7
  • 1
    One way would be to merge the 2 dfs on a common column, like 'Location' in this case. Try something like ```df1.merge(df2,how='left',on='Location')``` – sophocles Apr 02 '21 at 18:16

1 Answers1

0

Try merging the 2 data frames as sophocles points out in his edit. If you want to find out more on this topic, you can look at an already existing page here: Pandas Merging 101