我的数据框中“成绩”列下有一个“-”,并且此列中的所有条目都是一个对象。因此,当我尝试使用func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
// Override point for customization after application launch.
let audioSession = AVAudioSession.sharedInstance()
do {
try audioSession.setCategory(.playback, mode: .moviePlayback)
}
catch {
print("Setting category to AVAudioSessionCategoryPlayback failed.")
}
return true
}
将其转换为int时。此“-”不允许它发生并引发错误。
有人可以建议我用0代替'-'的代码吗?
感谢帮助
答案 0 :(得分:0)
如果要在特定列中替换
df["column_name"] = df["column_name"].replace(regex="-",value=0)
答案 1 :(得分:0)
您可以尝试这样:
df.replace(to_replace="-", value=0)
答案 2 :(得分:0)
或者可以将“-”转换为空值:
df["column_name"] = df["column_name"].apply(pd.to_numeric, errors="coerce")