【发布时间】:2018-10-20 10:46:41
【问题描述】:
我有一个这样的数据框:
import pandas as pd
test_df = pd.DataFrame({'foo':['1','2','92#']})
test_df
foo
0 1
1 2
2 92#
我想把类型转成int64:
test_df.foo.astype('int64')
但我收到错误消息,因为 '92#' 无法转换为 int64:
ValueError: int() 以 10 为底的无效文字:'92#'
所以我想删除所有无法转换为 int64 的行,并得到这样的结果:
foo
0 1
1 2
【问题讨论】:
标签: python pandas dataframe type-conversion