python - 根据 output2 值从 output1 打印行
问题描述
df1
slot Time Location User
56 2017-10-26 22:15:00 89 1
2 2017-10-27 00:30:00 54 1
20 2017-10-28 05:00:00 64 1
24 2017-10-29 06:00:00 2 1
91 2017-11-01 22:45:00 78 1
62 2017-11-02 15:30:00 99 1
91 2017-11-02 22:45:00 34 1
47 2017-10-26 20:15:00 465 2
1 2017-10-27 00:10:00 67 2
20 2017-10-28 05:00:00 5746 2
28 2017-10-29 07:00:00 36 2
91 2017-11-01 22:45:00 786 2
58 2017-11-02 14:30:00 477 2
95 2017-11-02 23:45:00 7322 2
df2
slot
2
91
62
58
我需要输出 df3 作为
slot Time Location User
2 2017-10-27 00:30:00 54 1
91 2017-11-01 22:45:00 78 1
91 2017-11-02 22:45:00 34 1
91 2017-11-01 22:45:00 786 2
62 2017-11-02 15:30:00 99 1
58 2017-11-02 14:30:00 477 2
如果这些是 csv 文件,那么我们可以加入它们
join File1 file2 > file3
但是我们怎样才能对 Jupyter notebook 中的输出做同样的事情呢?
解决方案
尝试isin
:
df1[df1.slot.isin(df2.slot)]
输出:
slot Time Location User
1 2 2017-10-27 00:30:00 54 1
4 91 2017-11-01 22:45:00 78 1
5 62 2017-11-02 15:30:00 99 1
6 91 2017-11-02 22:45:00 34 1
11 91 2017-11-01 22:45:00 786 2
12 58 2017-11-02 14:30:00 477 2
推荐阅读
- python - 在 django 中对 mysql 进行不区分大小写的搜索
- java - 使用 Java (SE8) 读取 CSV 文件
- java - java.lang.NoSuchMethodError: javax/validation/Validator.forExecutables 错误 Hibernate 5 和 Validation API 1.1
- html5-canvas - 调试 JS 修改某些特定的画布元素
- android - Resources.getIdentifier 替代
- python - 如何更有效地遍历数据框并根据两列值更新一个字段?
- javascript - 如何在 Electron 中的父窗口和子窗口之间发送数据
- mysql - 连接 3 个表的 MySQL 查询给出错误的结果
- sql - 如何识别小数点后只有零的记录?
- r - 在 r 中的列表列中的所有列表中将 numeric(0) 替换为 NA