簡體   English   中英

匹配 dataframe 列中的精確字符串

[英]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.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM