python - Python:从一个数据帧追加到一个新的数据帧
问题描述
我有一个包含 10 000 行的数据框。我需要根据条件将行提取到新的数据框中(其中名称在 name_list 中)
最简单的方法是什么
解决方案
Let's say this is your dataframe structure and name: dataframe = pd.DataFrame(record, columns = ['Name', 'Age', 'Stream', 'Percentage']
Accordingly, the new dataframe can be created as :
rslt_df = dataframe[dataframe['Name'].isin(name_list)]
alternatively, you can use :
rslt_df = dataframe.loc[dataframe['Name'].isin(name_list)]
推荐阅读
- javascript - 如何获取对象中每个数组的出现总数?
- c# - Protobuf 是否支持元组?
- python - 熊猫合并两个表,第二个表的一列转置
- regex - 如何强制复赛?
- firebase - 预期类型为“地图”的值
',但得到了一种类型 '() => Map ? - spring-boot - Spring boot:REST API 行为不一致后版本升级
- webrtc - 在 Windows 上的多线程 DLL 中构建 WebRTC
- collections - Powerapps 集合 - 向下钻取 3 个表?
- ios - iOS 15:如何在 SwiftUI 中启动应用程序时显示 ATT 对话框
- flutter - 获取 json 对象并在颤动中重新加载..哦,迷路了