我有以下数据,并试图删除dateTime列中有"!ENDMSG!"
的所有行
dateTime tradePrice tradeVolume aggVolume bid1 ask1 quote_counter
33501 2017-09-19 15:59:53 12545.5 1.0 54344.0 12545.0 12545.5 1567101.0
33502 2017-09-19 15:59:59 12545.0 1.0 54345.0 12545.0 12545.5 1567136.0
33503 2017-09-19 16:00:00 12545.0 1.0 54346.0 12544.5 12545.0 1567146.0
33504 2017-09-19 16:03:44 12544.0 17.0 54363.0 12544.0 12544.0 1567519.0
33505 !ENDMSG! NaN NaN NaN NaN NaN NaN
问题是dateTime
列的类型是object
,因此所有以下选项失败:
df[df.dateTime.str.contains('!ENDMSDG!') == False]
df[~df.dateTime.str.contains("!")]
df = df[~df['dateTime'].str.contains('!ENDMSDG!')]
print(df[df['dateTime'].str.match('!ENDMSDG!')])#another try to catch it
谢谢你的建议
似乎需要将
!ENDMSDG!
更改为!ENDMSG!
(而不是第二个D
字母):如果需要检查字符串的开头:
相关问题 更多 >
编程相关推荐