我如何加入具有唯一用户 ID 的 2 个数据框
how do i join 2 dataframe with unique userID
刚开始自学 python。所以我有 2 个像这样的 dfs。
df1:
userid
name
count
1
a
10
2
b
20
3
c
30
4
d
40
5
e
50
df2:
userid
name
count
6
f
60
7
g
70
8
h
80
4
d
40
2
b
20
由于两个 dfs 中都有相似的用户 ID,名称和计数,我想知道如何将这两个数据帧加入 df3,如下所示:
userid
name
count
1
a
10
2
b
20
3
c
30
4
d
40
5
e
50
6
f
60
7
g
70
8
h
80
谢谢
使用连接函数。
# create an array of your dataframes
alldfs = [df1, df2]
# concat them
df3 = pd.concat(alldfs)
在此处查看文档:https://pandas.pydata.org/pandas-docs/stable/user_guide/merging.html#concatenating-objects
刚开始自学 python。所以我有 2 个像这样的 dfs。
df1:
userid | name | count |
---|---|---|
1 | a | 10 |
2 | b | 20 |
3 | c | 30 |
4 | d | 40 |
5 | e | 50 |
df2:
userid | name | count |
---|---|---|
6 | f | 60 |
7 | g | 70 |
8 | h | 80 |
4 | d | 40 |
2 | b | 20 |
由于两个 dfs 中都有相似的用户 ID,名称和计数,我想知道如何将这两个数据帧加入 df3,如下所示:
userid | name | count |
---|---|---|
1 | a | 10 |
2 | b | 20 |
3 | c | 30 |
4 | d | 40 |
5 | e | 50 |
6 | f | 60 |
7 | g | 70 |
8 | h | 80 |
谢谢
使用连接函数。
# create an array of your dataframes
alldfs = [df1, df2]
# concat them
df3 = pd.concat(alldfs)
在此处查看文档:https://pandas.pydata.org/pandas-docs/stable/user_guide/merging.html#concatenating-objects