美文网首页
csv文件NA 空白的处理 2019-02-19

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

作者: 默写年华Antifragile | 来源:发表于2019-02-19 22:47 被阅读0次

    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

          本文链接:https://www.haomeiwen.com/subject/ozuqyqtx.html