我创建了一个机器学习网络应用程序,并将数据帧预测转换为用户可以下载的 .txt 文件
df.to_csv('pred.txt', sep=',', index=False)
输出格式应类似于(在本地主机 Windows 10 上):
x,y,z
1,2,3
4,5,6
7,8,9
但是,当我在 AWS Elastic Beanstalk (linux) 上部署 Web 应用程序并下载 pred.txt 时,格式变为:
x,y,z,1,2,3,4,5,6,7,8,9
为什么格式是这样的?我应该如何更改它以便格式与之前的格式一样?
最佳答案
Windows 和 Linux 有不同的换行符:
https://en.wikipedia.org/wiki/Newline#Representation
您可以通过将其作为 line_terminator
提供来强制 to_csv()
使用 Windows 换行符,如下所示:
df.to_csv('pred.txt', sep=',', index=False, line_terminator='\r\n')
关于python - 文本文件在 AWS Elastic Beanstalk(Flask Web 应用程序)上无法正确显示,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53398802/