问题描述
所以我的df看起来像这样:
x y group
0 53 10 csv1
1 53 10 csv1
2 48 9 csv0
3 48 9 csv0
4 48 9 csv0
... ... ... ...
我有一些文件取决于组名,除了x和y值外,还想在函数中使用它们。
到目前为止,我正在做以下事情:
dfGrouped = df.groupby('group') #group the dataframe
df['newcol'] = np.nan #crete new empty col
#use for loop to load file depending on group,note the file is very large,thats why I want to load it only once per group
for name,group in groupHashed:
file = open(name+'.txt')
#open the file
df['newcol'] = df[df['group'] == name].apply(lambda row: newValueFromFile(row.x,row.y,file),axis=1)
不幸的是,它似乎一开始就起作用了,不幸的是,newcol只保留了最后一个循环的值,并且似乎覆盖了先前用nan创建的值。有人知道吗?
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)