0

Using Pandas I made a dataframe that looks like this:

reqs    id_num      Airport User_name
162635  755892.392861   CHB jerry
3470    597553.214986   CHB george
81702   591434.723581   CHB albert
80982   591081.755452   CHB francios 
...
..

In a separate csv I have 2 columns that look like this in a file called user_age.csv

User_name Age
albert  30
jerry   22
george  15
francios 45
...
..

The result I would like is a dataframe that looks like this:

reqs    id_num      Airport User_name   Age
162635  755892.392861   CHB jerry       22
3470    597553.214986   CHB george      15
81702   591434.723581   CHB albert      30
80982   591081.755452   CHB francios    45
...
..

I'm not sure how to ask ^ questions. I tried to google around and couldnt find what I was looking to do. I would like to use the User_Name column as the index so that Ages drop in next to the correct username.

I can make a DF from the csv:

Ages = pd.read_csv("User_ages.csv") 

But I don't know how to merge with the existing df that contains the reqs id_num etc.

Seanny123
  • 8,776
  • 13
  • 68
  • 124
chowpay
  • 1,515
  • 6
  • 22
  • 44
  • 1
    Try `df1.merge(df2, how='left')`. `df2` contains ages and `df1` is with the airport information. – harvpan Jun 25 '18 at 18:52
  • 1
    I think its necessary to mention the common column `df1.merge(df2, how='left', on='User_name')` – YOLO Jun 25 '18 at 18:54
  • 1
    @YOLO, it is not necessary for the given minified example. If there are more than one overlapping columns and OP only wants to merge on `User_name`, it is necessary. – harvpan Jun 25 '18 at 18:55
  • 1
    ah thanks for clarification Harv @HarvIpan – YOLO Jun 25 '18 at 18:57
  • yes looking to merge user_name field. I will give this a try – chowpay Jun 25 '18 at 20:03

0 Answers0