2021年4月7日星期三

Python: Map a string value from one dataframe to another dataframe using a id, while creating a new column in the older dataframe

i turned a json file into a dataframe, but I am unsure of how to map a certain value from the json dataframe onto the existing data frame i have.

df1 =     # (2nd column does'nt matter just there)  
category_id tags
1 a
1 a
10 b
10 c
40 d
df2(json) =  
id title
1 film
2 music
3 travel
4 cooking
5 dance

I would like to make a new column in df1, that maps the titles from the df2 onto df1 corresponding to the category_id. I am sorry I am new to python programming. I know I can hard code the dictionary and key values and go from there. However I was wondering if there is a way with python/pandas to do this in an easier way.

https://stackoverflow.com/questions/66996387/python-map-a-string-value-from-one-dataframe-to-another-dataframe-using-a-id-w April 08, 2021 at 10:04AM

没有评论:

发表评论