我将从列表项中删除 '\n' (新行)。以下命令从 DataFrame 格式的 excel 文件中读取数据,然后将其转换为列表“bodylist”:
data = pd.read_excel (r'C:\Users\thmag\HealthUnlockSelenium\PopularPosts\out2.xlsx')
df = pd.DataFrame(data, columns= ['body'])
#print (df)
#convert df to list
bodylist = df.values.tolist()
bodylist= map(lambda s: s.strip(),bodylist)
for item in bodylist:
print (item)
但我有以下错误:
bodylist= map(lambda s: s.strip(),bodylist)
AttributeError: 'list' object has no attribute 'strip'