Reputation: 83
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:
Reading the excel file and choosing a specific component
df= pd.read_excel('Components.xlsx')
component_name = 'Name'
Forcing the index to be a certain column
df = df.set_index(['TECHNICAL DATA'])
Selecting data in a cell with df.loc
component_lifetime=df.loc[['Life time of Full unit'],component_name]
print(componet_lifetime)
What I get is:
TECHNICAL DATA
Life time of Full unit 20
Is it possible to hide all the index data and only print 20? Thank you ^^
Upvotes: 4
Views: 308
Reputation: 164753
Use pd.DataFrame.at
for scalar access by label:
res = df.at['Life time of Full unit', 'Name']
A short guide to indexing:
iat
/ at
for scalar access / setting by integer position or label respectively.iloc
/ loc
for non-scalar access / setting by integer position or label respectively.You can also extract the NumPy array via values
, but this is rarely necessary.
Upvotes: 1