简体   繁体   English

文本文件无法在AWS Elastic Beanstalk(Flask Web App)上正确显示

[英]Text file not displaying properly on AWS Elastic Beanstalk (Flask web App)

I have created a machine learning web app and I converted the dataframe predictions into a .txt file that users can download 我创建了一个机器学习Web应用程序,并将数据框预测转换为.txt文件,用户可以下载该文件

df.to_csv('pred.txt', sep=',', index=False)

and the output format should be like (on localhost Windows 10): 并且输出格式应类似于(在localhost Windows 10上):

x,y,z
1,2,3
4,5,6
7,8,9

However, when I deployed my web app on AWS Elastic Beanstalk (linux) and download the pred.txt, the format became like: 但是,当我在AWS Elastic Beanstalk(linux)上部署Web应用程序并下载pred.txt时,格式变为:

x,y,z,1,2,3,4,5,6,7,8,9

Why is the format like that and how should I change it so that the format is like the the prior format? 为什么是这样的格式,我应该如何更改它以使该格式类似于先前的格式?

Windows and Linux have different newline characters: Windows和Linux具有不同的换行符:

https://en.wikipedia.org/wiki/Newline#Representation https://en.wikipedia.org/wiki/Newline#Representation

You can force to_csv() to use the Windows newlines by providing it as line_terminator , like so: 您可以通过将to_csv()提供为line_terminator来强制to_csv()使用Windows换行符,如下所示:

df.to_csv('pred.txt', sep=',', index=False, line_terminator='\\r\\n')

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

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