Can't drop NAN with dropna in pandas

后端 未结 4 1919
心在旅途
心在旅途 2020-11-27 07:54

I import pandas as pd and run the code below and get the following result

Code:

traindataset = pd.read_csv(\'/Users/train.csv\')
print traindataset.d         


        
4条回答
  •  陌清茗
    陌清茗 (楼主)
    2020-11-27 08:07

    This is my first post. I just spent a few hours debugging this exact issue and I would like to share how I fixed this issue.

    I was converting my entire dataframe to a string and then placing that value back into the dataframe using similar code to what is displayed below: (please note, the code below will only convert the value to a string)

    row_counter = 0
    for ind, row in dataf.iterrows():
        cell_value = str(row['column_header'])
        dataf.loc[row_counter, 'column_header'] = cell_value
        row_counter += 1
    

    After converting the entire dataframe to a string, I then used the dropna() function. The values that were previously NaN (considered a null value by pandas) were converted to the string 'nan'.

    In conclusion, drop blank values FIRST, before you start manipulating data in the CSV and converting its data type.

提交回复
热议问题