[英]For in loop creating new Pandas DataFrames
I have 3 pd.DataFrame
and I want to apply the same operation (with a loop) creating 3 new DataFrames.我有 3 个pd.DataFrame
并且我想应用相同的操作(带有循环)创建 3 个新的 DataFrame。
d = {}
dfs=[d10,d11,acc]
for i in dfs:
a = (i.groupby('Variable').cumcount()).reset_index()
d[i] = pd.DataFrame(a)
I've tried to save it in a dictionary buT the error I've obtained is:我试图将它保存在字典中,但我得到的错误是:
TypeError: 'DataFrame' objects are mutable, thus they cannot be hashed TypeError: 'DataFrame' 对象是可变的,因此它们不能被散列
Store them in a list.将它们存储在列表中。 Not in a dictionary.字典里没有。
dfs=[d10,d11,acc]
for i in dfs:
a = (i.groupby('Variable').cumcount()).reset_index()
d.append( pd.DataFrame(a) )
Then, for calling each DataFrame:然后,调用每个 DataFrame:
d[0]-->d10 d[0]-->d10
d[1]-->d11 d[1]-->d11
d[2]-->acc d[2]-->累加
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.