gpt4 book ai didi

python - 从 Polybase 字符串中替换多个 ""

转载 作者:行者123 更新时间:2023-12-01 07:34:27 26 4
gpt4 key购买 nike

我有一个数据框,其中一列是错误。大多数情况下该列没有值,但在某些情况下它确实会获得值。

当我在其上使用 to_csv 时,该列就像

Country,Etl_Batch,Input_Date,Input_CampaignID,Tags,TargetGroupID,CampaignType,Duration,LeadTime,Notes,IsMultiChannel,IsRecurrence,Status,Error,Api_Executed_Datetime
RO,1511293247,2019-07-02,4177,,89,No Control,1,0,,False,True,Successful,,2019-07-16 15:26:00.696304
RO,1511293247,2019-07-02,4178,,232,Test/Control,3,0,,False,False,Successful,"Exception caught at HTTPHelper postXMLHTTPSRequest. Http response: <?xml version=""1.0"" encoding=""UTF-8""?><error><code>UMS-105</code><description>'activities' is not specified or invalid</description><severity>ERROR</severity></error>
Error message: The remote server returned an error: (400) Bad Request. ",2019-07-16 15:26:00.696304
RO,1511293247,2019-07-02,4179,,-1,Test/Control,3,0,,False,False,Successful,,2019-07-16 15:26:00.696304

当我使用此数据创建外部表时,出现了 Polybase 错误。

因为它有类似

的文本
"Exception caught at HTTPHelper postXMLHTTPSRequest. Http response: <?xml version=""1.0"" encoding=""UTF-8""?><error><code>UMS-105</code><description>'activities' is not specified or invalid</description><severity>ERROR</severity></error>
Error message: The remote server returned an error: (400) Bad Request. "

这是一个单个字符串,但由于它有 "" (中间有 2 个双引号),因此会导致错误。

我必须从 python 的字符串中删除 '""' (2 个双引号)。我该怎么做?

最佳答案

使用这个:

def app(row):
return str(row['Error']).replace("\"\""," ")

df['Error'] = df.apply(lambda x: app(x),axis = 1)
print(df['Error'])

关于python - 从 Polybase 字符串中替换多个 "",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57056035/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com