pandas 熊猫删除所有不是“日期时间”类型的行
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/39604094/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Pandas delete all rows that are not a 'datetime' type
提问by Lukasz
I've got a large file with login information for a list of users. The problem is that the file includes other information in the Date
column. I would like to remove all rows that are not of type datetime
in the Date
column. My data resembles
我有一个包含用户列表登录信息的大文件。问题是该文件在Date
列中包含其他信息。我想删除该类型不是所有行datetime
的Date
列。我的数据类似于
df=
Name Date
name_1 | 2012-07-12 22:20:00
name_1 | 2012-07-16 22:19:00
name_1 | 2013-12-16 17:50:00
name_1 | 4345 # type = 'int'
# type = 'float'
name_2 | 2010-01-11 19:54:00
name_2 | 2010-02-06 12:10:00
...
name_2 | 2012-07-18 22:12:00
name_2 | 4521
...
name_5423 | 2013-11-23 10:21:00
...
name_5423 | 7532
I've tried modifying the solution to
我已经尝试将解决方案修改为
finding non-numeric rows in dataframe in pandas?
Remove rows where column value type is string Pandas
and How-should-I-delete-rows-from-a-DataFrame-in-Python-Pandas
以及我应该如何从 Python-Pandas 中的 DataFrame 中删除行
to fit my needs.
以满足我的需要。
The problem is that whenever I attempt the change I either get an error or the entire dataframe gets deleted
问题是,每当我尝试更改时,我都会收到错误或整个数据框被删除