【发布时间】:2019-09-22 12:31:37
【问题描述】:
我的数据集如下所示。我正在尝试对我的 pandas 数据框进行子集化,以便仅选择所有 3 个人的响应。例如,在下面的数据框中,所有 3 个人的回答都是“我喜欢吃”和“你有美好的一天”。因此,只有那些应该被子集化。我不确定如何在Pandas 数据框中实现这一点。
注意:我是 Python 新手,请用你的代码解释一下。
数据帧示例
import pandas as pd
data = {'Person':['1', '1','1','2','2','2','2','3','3'],'Response':['I like to eat','You have nice day','My name is ','I like to eat','You have nice day','My name is','This is it','I like to eat','You have nice day'],
}
df = pd.DataFrame(data)
print (df)
输出:
Person Response
0 1 I like to eat
1 1 You have nice day
2 1 My name is
3 2 I like to eat
4 2 You have nice day
5 2 My name is
6 2 This is it
7 3 I like to eat
8 3 You have nice day
【问题讨论】:
标签: python-3.x string pandas dataframe text