如何使用 pandas 匹配来自两个不同数据集的记录?

How do I match records from two different datasets using pandas?

我有两个不同形状的数据框,例如:

Df1:

Index State city xyz
0 AL Ala .
1 CA . .
2 AK . .
3 AR . .
. . . .
. . . .

Df2:

Index State Lat Long
0 AL 121 4456
1 AK 42 1266
2 AZ 1421 -426
3 AR 121 456
. . . .

我想比较两个数据集中的州列,然后针对每个州将该州的纬度和经度值放入 df1 框架中。像这样的东西(使用 python、pandas 和 jupyter notebook):

Index State city xyz Lat Long
0 AL Ala . 121 4456
1 CA . . 198 4541
2 AK . . 42 1266
3 AR . . 121 456
. . . . ... ....

我不知道该怎么做。 感谢您阅读此问题,我还是初学者,如果这是一个愚蠢的问题,请见谅。

试试这个:

new_df = df1.merge(df2, on='State')