我认为您需要^{},如果您需要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
|