简体   繁体   English

如何通过替换连接两个不相等的数据集? (Python)

[英]How to join two unequal datasets with replacement? (python)

I am trying to manipulate and merge two uneven datasets to one.我正在尝试操纵两个不均匀的数据集并将其合并为一个。

Text Sentiment - Dataset one文本情感 - 数据集一

**text**   **sentiment**
angry      0
despair    0
fun        1
disappoint 0
joy        1
envy       0

Users - Dataset two用户 - 数据集二

**Gender** **Age** **Salary** **sentiment**
F          24       23000     1
F          45       70000     0
M          32       29000     0

What I want我想要的是

**text**   **sentiment** **Gender** **Age** **Salary**
angry      0             F          45       70000          
despair    0             M          32       29000
fun        1             F          24       23000    
disappoint 0             F          45       70000
joy        1             F          24       23000
envy       0             M          32       29000    

Eventually what I want is to assign the sentiments to the user.最终我想要的是将情绪分配给用户。 But the lack of User data means that the user has to be duplicated to be assigned to the Text Sentiment.但是缺少用户数据意味着必须复制用户才能分配给文本情感。 (first row of dataset one with sentiment of 0 with first row of dataset two with sentiment of 0 and so on, repeating users) (数据集一的第一行情绪为 0,数据集二的第一行情绪为 0,依此类推,重复用户)

I appreciate any help!感谢您的帮助!

You need to merge:您需要合并:

merged_df = df1.merge(df2, on='sentiment', how = 'left')

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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