python判断某列有值_检查pandas中的dataframe列中是否包含某些值

论坛 期权论坛 编程之家     
选择匿名的用户   2021-5-22 15:18   11   0

我认为您需要^{},如果您需要date列的值包含字符串07311954的行:print df[df['date'].astype(str).str.contains('07311954')]

或者如果date列的type是string:print df[df['date'].str.contains('07311954')]

如果要检查string1954列中date的最后4位:print df[df['date'].astype(str).str[-4:].str.contains('1954')]

样品:print df['date']

0 8152007

1 9262007

2 7311954

3 2252011

4 2012011

5 2012011

6 2222011

7 2282011

Name: date, dtype: int64

print df['date'].astype(str).str[-4:].str.contains('1954')

0 False

1 False

2 True

3 False

4 False

5 False

6 False

7 False

Name: date, dtype: bool

print df[df['date'].astype(str).str[-4:].str.contains('1954')]

cmte_id trans_typ entity_typ state employer occupation date \

2 C00119040 24K CCM MD NaN NaN 7311954

amount fec_id cand_id

2 1000 C00140715 H2MD05155

分享到 :
0 人收藏
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

积分:3875789
帖子:775174
精华:0
期权论坛 期权论坛
发布
内容

下载期权论坛手机APP