Advertisement
elena1234

convert string column into numeric in Python

Nov 16th, 2022 (edited)
114
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.58 KB | Source Code | 0 0
  1. df_auto['Kilometers'] = df_auto['Kilometers'].str.extract('(\d+\.?\d*)', expand=False).astype(int)
  2.  
  3. #########################################################
  4. df_jobs['Salary to'] = df_jobs['Salary'].str.findall(r'([-+]?\d*\.\d+|\d+)').str[-1]
  5. df_jobs['Salary from'] = df_jobs['Salary from'].astype(float)
  6.  
  7.  
  8. ###########################################################
  9.  
  10. df_auto['Kilometers_test'] = df_auto['Kilometers'].str.extract('(\d+\ \d*)', expand=False) # 40 000
  11. df_auto['Kilometers_test'] = pd.to_numeric(df_auto['Kilometers_test'].str.replace(" ", ""), errors = 'coerce')
  12.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement