这可能是非常愚蠢的事情,但我找不到在执行代码时不打印索引的解决方案。我的代码如下:
读取 Excel 文件并选择特定组件
df= pd.read_excel('Components.xlsx')
component_name = 'Name'
强制索引为某一列
df = df.set_index(['TECHNICAL DATA'])
使用 df.loc 选择单元格中的数据
component_lifetime=df.loc[['Life time of Full unit'],component_name]
print(componet_lifetime)
我得到的是:
技术数据
完整装置的使用寿命 20
是否可以隐藏所有索引数据,只打印20?谢谢你^^
Use pd.DataFrame.at https://pandas.pydata.org/pandas-docs/stable/generated/pandas.DataFrame.at.html用于标量访问by label:
res = df.at['Life time of Full unit', 'Name']
索引简短指南:
- Use
iat
/ at
分别用于通过整数位置或标签进行标量访问/设置。
- Use
iloc
/ loc
分别用于通过整数位置或标签进行非标量访问/设置。
您还可以通过提取 NumPy 数组values
,但这很少是必要的。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)