好吧,我检查了问题“删除 pandas 中的索引名称”,它不适用于我的情况。
所以我有一个 df,我用 pandas 对其进行规范化melt,然后用 对其进行非规范化pivot_table。现在我有以下 df,但我想删除这个索引名称variable。
这是 df:
df
variable Site Process cap-lo cap-up depreciation ... inv-cost max-grad min-fraction var-cost wacc
0 Mid Biomass plant 0.0 5000.0 25.0 ... 875000.0 1.500000e+15 0.0 1.4 0.07
1 Mid Coal plant 0.0 0.0 40.0 ... 600000.0 1.500000e+15 0.0 0.6 0.07
2 Mid Gas plant 0.0 80000.0 30.0 ... 450000.0 1.500000e+15 0.0 1.6 0.07
3 Mid Hydro plant 0.0 1400.0 50.0 ... 1600000.0 …Run Code Online (Sandbox Code Playgroud) 我得到了一个包含很多变量和约束的 pyomo 具体模型。
不知何故,我的模型中的变量之一违反了一个约束,这使得我的模型不可行:
WARNING: Loading a SolverResults object with a warning status into model=xxxx;
message from solver=Model was proven to be infeasible.
Run Code Online (Sandbox Code Playgroud)
有没有办法询问求解器不可行的原因?
例如,假设我有一个名为 的变量x,如果我定义以下 2 个约束,则模型将为 ofc。不可行的。
const1:
x >= 10
const2:
x <= 5
Run Code Online (Sandbox Code Playgroud)
我想要实现的目标是指出导致这种不可行性的约束和变量,以便我可以修复它。否则,对于我的大模型来说,很难找出导致这种不可行性的原因。
IN: write_some_comment
OUT: variable "x" cannot fulfill "const1" and "const2" at the same time.
Run Code Online (Sandbox Code Playgroud) 我想选择一个名为'Mid'的行,而不会丢失它的索引'Site'
以下代码显示了数据帧:
m.commodity
Run Code Online (Sandbox Code Playgroud)
price max maxperstep
Site Commodity Type
Mid Biomass Stock 6.0 inf inf
CO2 Env 0.0 inf inf
Coal Stock 7.0 inf inf
Elec Demand NaN NaN NaN
Gas Stock 27.0 inf inf
Hydro SupIm NaN NaN NaN
Lignite Stock 4.0 inf inf
Slack Stock 999.0 inf inf
Solar SupIm NaN NaN NaN
Wind SupIm NaN NaN NaN
North Biomass Stock 6.0 inf inf
CO2 Env 0.0 inf inf
Coal Stock 7.0 inf inf
Elec Demand NaN NaN …Run Code Online (Sandbox Code Playgroud) 我有一个通过python字典键组成的列表; list(dict.keys())。
dict.keys()
dict_keys(['South', 'North'])
Run Code Online (Sandbox Code Playgroud)
我想在类似的每个元素中添加一个字符串list = ['South', 'North']:
my_string = 'to_'
最后我想要 list = ['to_South', 'to_North']
有什么我可以使用的方法吗?
就像是:
list.add_beginning_of_each_element('to_')
Run Code Online (Sandbox Code Playgroud) 假设我有两个 pyomo 集 A 和 B,其中包含以下元素:
m.A = {1,2,3,4,5}
m.B = {a,b,c,d,5}
Run Code Online (Sandbox Code Playgroud)
我想检查一下;如果 A 有一些元素也在 B 中:
编辑:
那么以下不起作用:
if m.A & m.B is not None:
raise ValueError
Run Code Online (Sandbox Code Playgroud)
至少对于我的情况,当m.A = [None]和 时m.B = ['some_string'], if 语句也会被触发,但bool(m.A & m.B)正在工作。
我有以下 matplotlib
我想将 x-ticks 分成 2 行而不是 1 行,因为有时它们太长了,这就是为什么它们会出现另一行,然后无法读取 x-ticks。
请记住 X-ticks 不是硬编码的,它们正在发生变化。所以并不总是相同的x-ticks。
因此,对于以下示例,如果我拥有而不是to Schleswig-Holstein我可以拥有,那就太好了:
to Schleswig-
Holstein
Run Code Online (Sandbox Code Playgroud)
我如何将字符串放在-x 刻度的换行符之后?或者只是在说 10 个字母之后我想换一行
顺便说一句,如果我可以像上面的示例一样将所有文本居中,那也很好
所以跟随也可以,但不是最好的。
to Schleswig-
Holstein
Run Code Online (Sandbox Code Playgroud)
PS:这是我使用的代码:
# create figure
fig = plt.figure()
# x-Axis (sites)
i = np.array(i)
i_pos = np.arange(len(i))
# y-Axis (values)
u = urbs_values
o = oemof_values
plt.bar(i_pos-0.15, list(u.values()), label='urbs', align='center', alpha=0.75, width=0.2)
plt.ticklabel_format(axis='y', style='sci', scilimits=(0, 0))
plt.bar(i_pos+0.15, list(o.values()), label='oemof', align='center', alpha=0.75, width=0.2)
plt.ticklabel_format(axis='y', style='sci', scilimits=(0, 0))
# tick names
plt.xticks(i_pos, …Run Code Online (Sandbox Code Playgroud) 我想知道是否有办法使用 NVIDIA Cuda 通过 GPU 求解 Pyomo 具体模型。
我查看了https://developer.nvidia.com/how-to-cuda-python,并看到了有关它的视频。事实证明你的输入参数是否可以被 numpy 识别,例如;np.float32、np.float64 等...可以通过 GPU 进行编译/求解,
我们使用一个函数来创建所有模型并用以下方法求解:
optim = SolverFactory('glpk')
optim = setup_solver(optim, logfile=log_filename)
result = optim.solve(prob, tee=True)
Run Code Online (Sandbox Code Playgroud)
在这种情况下,我们求解函数的输入将是 prob(一个 pyomo 具体模型)。有没有办法通过 GPU 而不是 CPU 来解决这个问题?
谢谢你!
python ×5
pyomo ×3
dataframe ×2
pandas ×2
constraints ×1
cuda ×1
dictionary ×1
element ×1
feasibility ×1
gpu ×1
list ×1
matplotlib ×1
multi-index ×1
numpy ×1
set ×1
string ×1
variables ×1