Python 熊猫0.24在gzip csv文件中写入额外的回车

Python 熊猫0.24在gzip csv文件中写入额外的回车,python,pandas,Python,Pandas,在Windows下,标准EOL(行尾)终止符是一个回车符,后跟一个换行符。当在数据帧上使用to_csv方法时,我得到的就是这个。然而,当我使用to_csv方法编写gzip压缩文件时,我在文件中得到两个回车 import pandas as pd, sys, gzip, zlib print("python:", sys.version) print("pandas:", pd.__version__) print("zlib :", zlib.ZLIB_RUNTIME_VERSION) df=

在Windows下,标准EOL(行尾)终止符是一个回车符,后跟一个换行符。当在数据帧上使用to_csv方法时,我得到的就是这个。然而,当我使用to_csv方法编写gzip压缩文件时,我在文件中得到两个回车

import pandas as pd, sys, gzip, zlib
print("python:", sys.version)
print("pandas:", pd.__version__)
print("zlib  :", zlib.ZLIB_RUNTIME_VERSION)
df=pd.DataFrame(data={'c0':['a','b'], 'c1':['c','d']})
print(df)
# Under Windows the EOL marker is \r\n, so this works as expected
df.to_csv('df.csv', index=None)
with open('df.csv', 'rb') as f:
    print("df.csv, default terminator   :", f.read())
# with gzip it writes \r\r\n as EOL, looks like a bug
df.to_csv('df.csv.gz', index=None)
with gzip.open('df.csv.gz', 'rb') as f:
    print("df.csv.gz, default terminator:", f.read())
# when specifying only a single '\n' that's what is written
df.to_csv('df.csv', index=None, line_terminator='\n')
with open('df.csv', 'rb') as f:
    print("df.csv, '\\n' terminator      :", f.read())
# when specifying only a single '\n' gzip it writes \r\n as EOL as desired
df.to_csv('df.csv.gz', index=None, line_terminator='\n')
with gzip.open('df.csv.gz', 'rb') as f:
    print("df.csv.gz, '\\n' terminator   :", f.read())
以下是输出:

python: 3.6.8 |Anaconda custom (64-bit)| (default, Dec 30 2018, 18:50:55) [MSC v.1915 64 bit (AMD64)]
pandas: 0.24.0
zlib  : 1.2.11
  c0 c1
0  a  c
1  b  d
df.csv, default terminator   : b'c0,c1\r\na,c\r\nb,d\r\n'
df.csv.gz, default terminator: b'c0,c1\r\r\na,c\r\r\nb,d\r\r\n'
df.csv, '\n' terminator      : b'c0,c1\na,c\nb,d\n'
df.csv.gz, '\n' terminator   : b'c0,c1\r\na,c\r\nb,d\r\n'
这显然与之前在会议上讨论的一个问题有关。我的问题是压缩文件和未压缩文件的行为不同。这是一个已知的问题吗