简体   繁体   English

如何处理附加在 windows 生成的 csv 末尾的空行?

[英]How to deal with null row appended at the end of windows generated csv?

I wrote a function to deal with the null values in the csv before passing it to a forecasting model我写了一个函数来处理 csv 中的空值,然后再将其传递给预测模型

if do_nulls_exist == True:
    print('found a null value')
    null_rows = pd.isnull(data)
    print('######### ORIGINAL ROWS THAT NEED UPDATING ##############')
    print(null_rows)
    # Need to add 2 to each value in null_rows because there

    print('######### ROWS + 2 = ACTUAL ROW NUMBERS IN CSV ##############')
    update_these_rows = []
    for x in null_rows:
        update_these_rows.append(int(x)+2)

    print(update_these_rows)

    emit('error', {'data': update_these_rows})

后台出错

As you can see the there is a null row appended at the end (Row no 36)如您所见,末尾附加了一个空行(第 36 行)

Pls guide me as to how I can remove this null row.请指导我如何删除这个空行。 Thanks!谢谢!

Before passing CSV to forecast model you can apply dropna() function on Dataframe.在将 CSV 传递给预测模型之前,您可以在 Dataframe 上应用dropna()函数。 It will delete all null row's它将删除所有空行

    df = df.dropna()

Refe Link : dropna参考链接: dropna

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM