简体   繁体   中英

Create new column based on two columns (different length) from different data frames

I have two data frames df3 ['categories'] and df8 with different length.

 df3['categories']
 1         (0.0, 0.0444]
 2         (0.0, 0.0444]
 ...
 26     (0.0444, 0.0888]
 27     (0.0444, 0.0888]
 ...

and

df8
categories       First_value(cm)
(0.0, 0.0444]       0.047999
(0.0444, 0.0888]    0.864710
(0.0888, 0.133]     1.002046
(0.133, 0.178]      1.093647

I want to create a new column call df3 ['first_values_cm'] next to df3 ['categories'] which contains the value from each category from df8.

How can I link one data frame to the other and fill the new column with values?

I've tried this code... but it seems that I'm lost

df3['First_value(cm)']= df3.apply(lambda row: 'df81' if row.categories ==  ) 

df3['First_value(cm)']= np.where(df3['categories'] == )

Any ideas?, suggestion?

您应该问堆栈溢出问题,因为您的帖子仅与编程有关,而与数据科学问题无关。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM