Skip to content

DataFrame.to_csv not using correct line terminator value #20353

Closed
@bbibentyo

Description

@bbibentyo

Method 1:

        data_frame.to_csv(file_path, sep=self.delimiter, float_format='%.2f',
                                  index=False, line_terminator='\n')

Method 2:

        with open(file_path, mode='w', newline='\n') as f:
            data_frame.to_csv(f, sep=self.delimiter, float_format='%.2f',
                              index=False)

Problem description

I noticed a strange behavior when using pandas.DataFrame.to_csv method on Windows (pandas version 0.20.3). When calling the method using method 1 with a file path, it's creating a new file using the \r line terminator, I had to use method two to make it work.

Metadata

Metadata

Assignees

No one assigned

    Labels

    IO CSVread_csv, to_csvWindowsWindows OS

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions