熊猫:在列值之间插值以返回索引名称

时间:2020-09-20 17:15:41

标签: python pandas python-3.6

我想在以下代码中返回with cProfile.run... def onCreateInterface(): widget = MyQtWidget() return widget sqoop import \ --connect jdbc:mysql://localhost/ksvr \ --username root \ --password abcdefgh \ --table ksvr_tables \ --target-dir /bigdata/tables1/ksvr_tables.csv \ -m 1 。我认为我走在正确的轨道上,但是不确定如何推进,我已经附加了代码和输出

编辑:我愿意按照自己的方式设计更改。

例如index name中的cost,它应返回a

test_data

1 个答案:

答案 0 :(得分:1)

这样吗?

def get_treatment(material, func_class, hci):
    return dft[(dft['mat'] == material) &
               (dft['class'] == func_class) &
               (dft['hci'].astype(int) >= hci)]['cost']


# test_data = ... #

for k, v in test_data.items():
    res = get_treatment(v['mat'], v['class'], v['hci'])
    print (k, res, '\n')

输出:

> a min_asp_art    100000
> maj_asp_art    350000
> Name: cost, dtype: object 

> b Series([], Name: cost, dtype: object) 

> c min_asp_col    100000
> Name: cost, dtype: object 

> d min_asp_art    100000
> maj_asp_art    350000
> Name: cost, dtype: object 

> e min_chip_col    30000
> Name: cost, dtype: object 

> f Series([], Name: cost, dtype: object) 

> g min_asp_art    100000
> maj_asp_art    350000
> Name: cost, dtype: object 

> h min_asp_art    100000
> Name: cost, dtype: object 

> i min_asp_art    100000
> maj_asp_art    350000
> Name: cost, dtype: object