Python:如何在执行时隐藏索引 [英] Python: How to hide index when executing

查看:99
本文介绍了Python:如何在执行时隐藏索引的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这可能很愚蠢,但是我找不到执行代码时不打印索引的解决方案.我的代码去了:

It's probably something very stupid but I can't find a solution to not print the indexes when executing the code.My code goes:

读取excel文件并选择特定组件

Reading the excel file and choosing a specific component

df= pd.read_excel('Components.xlsx')
component_name = 'Name'

强制索引为特定列

df = df.set_index(['TECHNICAL DATA']) 

使用df.loc在单元格中选择数据

Selecting data in a cell with df.loc

component_lifetime=df.loc[['Life time of Full unit'],component_name]
print(componet_lifetime)

我得到的是:

技术数据

完整单元20的寿命

是否可以隐藏所有索引数据并仅打印20个?谢谢^^

Is it possible to hide all the index data and only print 20? Thank you ^^

推荐答案

使用 pd.DataFrame.at ,用于按标签进行标量访问:

res = df.at['Life time of Full unit', 'Name']

索引编制的简短指南:

  1. 分别使用iat/at进行标量访问/通过整数位置或标签进行设置.
  2. 分别使用iloc/loc进行非标量访问/通过整数位置或标签进行设置.
  1. Use iat / at for scalar access / setting by integer position or label respectively.
  2. Use iloc / loc for non-scalar access / setting by integer position or label respectively.

您还可以通过values提取NumPy数组,但这很少有必要.

You can also extract the NumPy array via values, but this is rarely necessary.

这篇关于Python:如何在执行时隐藏索引的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆