4

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 ^^

1
  • 4
    Adding .values (component_lifetime=df.loc[['Life time of Full unit'],component_name].values) should do the job Commented Dec 18, 2018 at 16:36

1 Answer 1

1

Use pd.DataFrame.at for scalar access by label:

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

A short guide to indexing:

  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.

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

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.