首页 > 解决方案 > Python:从一个数据帧追加到一个新的数据帧

问题描述

我有一个包含 10 000 行的数据框。我需要根据条件将行提取到新的数据框中(其中名称在 name_list 中)

最简单的方法是什么

标签: pythondataframe

解决方案


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)]


推荐阅读