Reu*_*eut 2 python string digits pandas
我有以下熊猫数据框:
>>>ID WKT
0 4272 Point(4.21189 3.1298)
1 2345 Point(None None)
2 1254 Point (3.8945 4.6712)
...
Run Code Online (Sandbox Code Playgroud)
我想删除“WKT”列中不包含任何数字的行,例如第 1 行。我看到有 isnumeric() 等函数,但我不想检查单元格中的所有字符是否都是数字,但前提是它包含数字或 nit,如果不包含则将其删除。
我想要的输出应该是这样的:
>>>ID WKT
0 4272 Point(4.21189 3.1298)
2 1254 Point (3.8945 4.6712)
...
Run Code Online (Sandbox Code Playgroud)
您可以str.contains在 WKT 列上使用方法调用
df[df['WKT'].str.contains('\\d')]\n\n ID WKT\n0 4272 Point(4.21189 3.1298)\n2 1254 Point (3.8945 4.6712)\nRun Code Online (Sandbox Code Playgroud)\n\\d\\d matches a digit (equal to [0-9])\n\n+ Quantifier \xe2\x80\x94 Matches between one and unlimited times, \nas many times as possible, giving back as needed (greedy)\nRun Code Online (Sandbox Code Playgroud)\n
| 归档时间: |
|
| 查看次数: |
2492 次 |
| 最近记录: |