【发布时间】:2018-11-11 01:04:06
【问题描述】:
我在循环中从大数据帧中创建了子数据帧,并且我一直在尝试在循环内的这些子数据帧上创建一列:
Partidas=data2['Partida'].unique()
Partida2=[w.replace(' ','_') for w in Partidas]
for i, j in zip(Partidas,Partida2):
globals()['%s' % j]=data2.loc[data2['Partida']==i]
for k in globals().items()
['%s' % k]['Top 10']='a'
因此,我为每个“Partida”创建了一个数据框,它们的名称就是它们所代表的“Partida”的名称。现在我想向那些名为“Top 10”的数据框添加一列,但出现以下错误:
TypeError: not all arguments converted during string formatting
您知道是否有一种方法可以在循环中添加该列,而不必为每个数据框添加该列的数据框? 提前致谢!
【问题讨论】:
-
首先,为什么要在这样的循环中创建全局变量?另外,您希望第二个循环做什么?
标签: python pandas loops for-loop global