[英]How to format string without leading zeros and + - as integer in python pandas?
我在 pandas dataframe 中有一列帶有字符串的行,如下所示:
+0094
-0082
我將如何替換列中的所有值,以便它們的格式如下:
94
-82
pandas
足夠聰明,可以通過數據幀的astype
方法來解決。
所以你的方法是:
df['col of interest'] = df['col of interest'].astype(int)
我建議使用pd.to_numeric
因為它提供了比.astype
更大的靈活性:
df['col'] = pd.to_numeric(df['col'])
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.