如何获得所需的价值?

2024-09-28 19:19:45 发布

您现在位置:Python中文网/ 问答频道 /正文

事实证明,答案中有这样的问题。但我只想看['store1']。你需要做什么?你知道吗

def answer_ups():
    import pandas as pd
    bla = pd.DataFrame([{'Name': 'Chris', 'Item Purchased': 'Sponge', 'Cost': 202.50},
                   {'Name': 'Kevyn', 'Item Purchased': 'Kitty Litter', 'Cost': 232.50},
                   {'Name': 'Filip', 'Item Purchased': 'Spoon', 'Cost': 100}],
                            index=['Store 1', 'Store 2', 'Store 3'])
    bla ['NewCost'] = bla ['Cost'] * 1.15  
    ququ = bla ['NewCost'].sort_values(ascending=False)
    return ququ [1:2]

answer_ups()

应答(存储1 232.875)


Tags: store答案answernameimportdefitempd
3条回答

如果您只需要'store1'部分,只需返回这个return ['Store 1', ququ['Store 1']]

它将输出:['Store 1', 232.87499999999997]

print(type(ququ))
<class 'pandas.core.series.Series'>

因为函数answer_ups()ququSeries,所以这里给出了一些Series indexing。你知道吗

>>print(ququ.index) 
Index(['Store 2', 'Store 1', 'Store 3'], dtype='object')
>>print(ququ.index[1])
Store 1
>>print(ququ[1])
232.875
>>print(ququ[1:2])
Store 1    232.875

考虑到他的观点,你的qqu变量是

ququ = 
    Store 2    267.375
    Store 1    232.875
    Store 3    115.000

第一列是可以通过这种方式访问的索引:

ququ.index[1] = 
    'Store 1'

第二列是NewCost值,您可以通过以下方式访问:

ququ[1] = 
    232.875

相关问题 更多 >