![](/img/trans.png)
[英]Merging two pandas dataframe by a string type column allowing not exact match
[英]Match exact string in dataframe column
如何在 dataframe 列中找到字符串的完全匹配?
目前,我正在 col_8 中搜索字符串 '1',它為第 2 行返回 True,但我希望它為 false,因為它實際上是 12。提前致謝!
df['new'] = np.where(df['col_8'].str.contains('1'),1,0)
print(df)
col_8 col_9 new
0 1,2,3 7 1
1 1,3,8 10 1
2 12 8 1
3 9 3 0
這會起作用
df['new'] = np.where(df['col_8'].str.contains('1,'),1,0)
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.