csv文件NA 空白的处理 2019-02-19

https://code.likeagirl.io/how-to-use-python-to-remove-or-modify-empty-values-in-a-csv-dataset-34426c816347

Solution 1: Replace empty/null values with a space

  • Fill all null or empty cells in your original DataFrame with an empty space and set that to a new DataFrame variable, here, called ‘modifiedFlights’*. modifiedFlights=flights.fillna(“ “)
  • Verify that you no longer have any null values by running modifiedFlights.isnull().sum()
  • Save your modified dataset to a new CSV, replacing ‘modifiedFlights.csv’ with whatever you would like to name your new file. modifiedFlights.to_csv('modifiedFlights.csv',index=False)
  • If you wish, you can replace your original DataFrame, using flights=flights.fillna(" ")

Solution 2: Remove rows with empty values

  • If there are only a few null values and you know that deleting values will not cause adverse effects on your result, remove them from your DataFrame and store that in a new DataFrame.
    modifiedFlights = flights.dropna()
  • Verify that you no longer have any null values by running modifiedFlights.isnull().sum()
  • Save your modified dataset to a new CSV, replacing ‘modifiedFlights.csv’ with whatever you would like to name your new file. modifiedFlights.to_csv('modifiedFlights.csv',index=False)
  • If you wish, you can replace your original DataFrame, using flights=flights.dropna()

你可能感兴趣的:(csv文件NA 空白的处理 2019-02-19)