0

I have a file which has all datatypes as string. I want to type cast the data.

for s3_file in keys:
    analytics_df = pd.read_csv(s3_file, encoding="utf8")
    analytics_df = analytics_df.juice.astype(float).fillna(0.0)
    print(analytics_df.dtypes)

I am getting these errors:

ValueError: could not convert string to float: 'None'
Avenger
  • 793
  • 11
  • 31
  • Try replacing the “None” strings with np.nan. Then cast to float. – jkr Mar 07 '23 at 13:06
  • replace `analytics_df.juice.astype(float).fillna(0.0)` by `pd.to_numeric(analytics_df['juice'], errors='coerce').fillna(0.0)` – mozway Mar 07 '23 at 13:10

0 Answers0