【发布时间】:2021-08-19 23:51:27
【问题描述】:
我在 excel 中有 5 张不同参数的工作表。
history
idx history
1 1daybehind
recorded
idx recorded
1 daily
optmethod
idx opt optmethod
1 backprop x1
2 convex x2
3 monte x3
4 monte x4
optpara
idx optpara
1 x1x2
2 x3x4
3 x1x4
4 x2x3
filter
idx filter
1 x1>0
2 x2>0
3 x3>0
4 x4>0
我想创建行条目的排列,因此我想以下表结束所有可能的情况。这只是前 6 行。
scenario history recorded optmethod optpara filter
1 1 1 1 1 1
2 1 1 1 1 2
3 1 1 1 1 3
4 1 1 1 1 4
5 1 1 1 2 1
6 1 1 1 2 2
...
所以第一行,场景1 将是1 1daybehind,1 daily,1 backprop,1 x1x2,1 x1>1
我尝试了以下代码,
for name,sheet in sheet_dict.items():
print(name)
if name == 'history':
sndf = sheet
sndf = sndf[['idx']]
sndf = sndf.rename(columns={'idx':name})
else:
sndf['key'] = 1
sheet = sheet[['idx']]
sheet = sheet.rename(columns={'idx':name})
sheet['key'] = 1
sndf = pd.merge(sndf, sheet, on ='key').drop("key", 1)
sndf.index.names = ['scenario']
sndf.to_csv('scenarionum.csv',index=True)
但我最终得到了这个。我的行数正确,但每个单元格都填满了1s。
scenario history recorded optmethod optpara filter
0 1 1 1 1 1
1 1 1 1 1 1
2 1 1 1 1 1
3 1 1 1 1 1
4 1 1 1 2 1
5 1 1 1 2 1
我相信这个问题的答案是交叉连接,但我不确定如何去做。
我做错了什么,我该如何解决???
【问题讨论】:
标签: pandas permutation scenarios