Forum Discussion

Anonymous's avatar
Anonymous
Not applicable
6 years ago
Solved

dataset to csv with python return extra blank row at the end

dear all, Using python in power query to export my dataset to csv creates an extra blank row at the end of the exported dataset while this is not in my dataset in power query. im using this code: ...
  • v-lid-msft's avatar
    v-lid-msft
    6 years ago

    Hi Anonymous ,

     

    Could you please try to change the size -1 to size -2? We may need to delete \r\n in the end (it mean delete 2 char in size).

     

     

    import pandas
    import os
    import matplotlib
    
    filepath = r"D:\test.csv"
    
    dataset.to_csv(filepath,sep=',', encoding='utf-8-sig', index=False)
    
    with open(filepath, 'r+') as f:
        f.seek(0,2)                    
        size=f.tell()               
        f.truncate(size-2)
    

     

     


    Best regards,