【发布时间】:2019-04-29 13:07:59
【问题描述】:
我正在使用 Python3 从 Excel 电子表格中读取一列:
import pandas as pd
from pandas import ExcelFile
df = pd.read_excel('MWE.xlsx', sheet_name='Sheet1')
print(df)
col1 col2
0 starts normal egg, bacon
1 still none the wiser egg, sausage, bacon
2 maybe odd tastes egg, spam
3 or maybe post-war egg, bacon, spam
4 maybe for the hungry egg, bacon, sausage, spam
5 bingo spam, bacon, sausage, spam
我想将 col2 减少为 col2 中单词的单个列表(例如 egg、bacon、...)。
df.col2.ravel() 似乎将col2 简化为字符串列表。
df.col2.flatten() 产量
AttributeError: 'Series' object has no attribute 'flatten'
【问题讨论】: