我构建了pandas数据框df:
df.info()
<class 'pandas.core.frame.DataFrame'>
RangeIndex: 13000 entries, 0 to 12999
Data columns (total 4 columns):
at 1625 non-null object
screenName 1625 non-null object
espacio 1625 non-null object
promo 1625 non-null object
dtypes: object(4)
memory usage: 406.3+ KB
df['at'].describe()
count 1625
unique 1
top @
freq 1625
Name: at, dtype: object
我正在尝试创建一个新列,逐行粘贴每列的所有字符串:
df["tweet"] = df.at+df.screenName+df.espacio+df.promo
我收到此错误:
TypeError: unsupported operand type(s) for +: '_AtIndexer' and 'str'
我认为这是因为所有列df ['at']都以“@”归档,因为当我将该列从代码中删除时它会起作用。我该如何解决这个问题?
答案 0 :(得分:1)
df["tweet"] = df.at.astype(str)+df.screenName+df.espacio+df.promo