且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

pandas Read_CSV报价问题

更新时间:2023-01-29 19:32:22

我认为您需要 apply :

I think you need str.strip with apply:

import pandas as pd
import io

temp=u"""'colA'|'colB'
'word"A'|'A'
'word'B'|'B'"""

#after testing replace io.StringIO(temp) to filename
df = pd.read_csv(io.StringIO(temp), sep='|')

df = df.apply(lambda x: x.str.strip("'"))
df.columns = df.columns.str.strip("'")
print (df)
     colA colB
0  word"A    A
1  word'B    B