Pandas:将一个数据帧的特定列连接到另一个数据帧

2024-09-30 20:17:47 发布

您现在位置:Python中文网/ 问答频道 /正文

我在熊猫中有两个数据帧:

电影

+---+------------------------------+--------------+-----------+
|   | movie title                  | genre        | tconst    |
+---+------------------------------+--------------+-----------+
| 0 | Edison Kinetoscopic Record   | Documentary  | tt0000008 |
+---+------------------------------+--------------+-----------+
| 1 | La sortie des usines Lumière | Documentary  | tt0000010 |
+---+------------------------------+--------------+-----------+
| 2 | The Arrival of a Train       | Documentary  | tt0000012 |
+---+------------------------------+--------------+-----------+
| 3 | The Oxford and Cambridge     | NaN          | tt0000025 |
+---+------------------------------+--------------+-----------+
| 4 | Le manoir du diable          | Short|Horror | tt0000091 |
+---+------------------------------+--------------+-----------+

船员

^{pr2}$

如何创建一个新的数据帧,其中我将导演列仅加入电影数据帧(使用tconst column)?在


Tags: the数据电影titlemovierecordlades
1条回答
网友
1楼 · 发布于 2024-09-30 20:17:47

尝试:

pd.merge(movies, crew[["tconst", "directors", "year"]], on="tconst", how="left")

on参数告诉函数要在键tconst上合并,how参数告诉函数如何处理两个数据帧之间不相交(共享)的行。在

相关问题 更多 >