简体   繁体   English

用python中的空格替换换行符

[英]Replace newline chars with space in python

Am using SQL to get the data from salesforce api using python. 我正在使用SQL使用python从salesforce api获取数据。

The output is writing into csv file. 输出正在写入csv文件。

When I tried with the below statement, to replace the newlines, its not replacing all of them. 当我尝试使用以下语句替换新行时,不会替换所有新行。 For example, for one record we are getting multiple lines of data in multiple fields, leads to lot more records, instead of actual records that to in a wrong format. 例如,对于一条记录,我们在多个字段中获得多行数据,导致产生更多的记录,而不是实际记录格式错误。

tmp.append(str(record['Description']).replace('\r\n',''))

Used this link to write the json data into csv 使用此链接将json数据写入csv

Any help would be appreciated. 任何帮助,将不胜感激。

Thanks Venkat 感谢Venkat

Have you tried to use pandas to read the data? 您是否尝试过使用熊猫读取数据?

you can do 你可以做

import pandas as pd
pd.read_csv('filepath.csv', sep=',')

or you can do 或者你可以做

pd.read_json('data.json', orient='records')

Do any of these work? 这些工作有吗?

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

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