【发布时间】:2017-06-19 00:32:45
【问题描述】:
我是编程和 python 的新手。我有一个由 pandas 模块创建的 DataFrame。数据集的索引列是“Rho”、“Capacity”和“Model-Version”。基于这些因素,我进行了一些模拟,并找到了每个运行 5 次的收入。这些列分别表示“平均值”、“下限”和“上限”。
现在我想为每个特定的 Rho 和容量找到最佳收入。所以我应该比较不同模型的上限和下限。如果一行的下限高于另一个上限的值,我应该删除具有较小上限的行。
这是我目前拥有的代码:
from pandas import *
df_rev = DataFrame.from_csv(path="revenue_total.csv", index_col=[3, 4, 5])
print(df_rev.iloc[0][2])
# removing those revenues in a class that are low:
for index1, row1 in df_rev.iterrows():
for index2, row2 in df_rev.iterrows():
if index1[0] is index2[0] and index1[1] is index2[1]:
if row1[1] > row2[2]:
df_rev = df_rev.drop(df_rev.index[index2])
elif row2[1] > row1[2]:
df_rev = df_rev.drop(df_rev.index[index1])
print(df_rev)
但是,我知道这行不通。有人知道我该怎么做吗?
谢谢
【问题讨论】: