通过匹配字符串是有效的..但是通过查找以“ Bing”或“ Google”开头的任何内容都会更好!
Dataframe:
number platform rds
0 200 BingBrand 56
1 200 BingNonBrand 56
2 200 BingNonBrand 56
3 151 GoogleNonBrand 56
4 1651 GoogleDisplay 56
5 626 Bing 56
6 626 BingNonBrand 56
7 125 GoogleBrand 56
# It is working but only for the last condition in the brackets,
example: BingBrand, GoogleBrand
# creating two new dataframes for each
cw_bing = cw[cw["platform"] == ('Bing' and 'BingNonBrand' and 'BingBrand' )]
cw_google = cw[cw["platform"] == ('GoogleNonBrand'and 'GoogleDisplay'
and 'Google' and 'GoogleBrand')]
尝试按以“必应”或“ Google”开头的任何行进行拆分
# Doesnt work
# cw_bing = cw[cw["vendorname"].filter(regex='Bing.*')]
# cw_google = cw[cw["vendorname"].filter(regex='Google.*')]
最终结果应该是这样
df 1 =
BingBrand 56
1 200 BingNonBrand 56
2 200 BingNonBrand 56
5 626 Bing 56
6 626 BingNonBrand 56
df2 =
3 151 GoogleNonBrand 56
4 1651 GoogleDisplay 56
7 125 GoogleBrand 56
答案 0 :(得分:1)
您可以使用contain。
bing = df[df.platform.str.contains('Bing')]
google = df[df.platform.str.contains('Google')]