0

I have been trying to find the display the top 10 companies from the list of 2000 based on a particular column. but the issue is when I input the variable to display the data set, it shows the index and I wanted to know is this can be done without using Print statement.

My current code is

forbes_global = pd.read_csv("Forbes_Global_2000_2019.csv")
profit_assest_company=forbes_global[['Company','Profits as % of Assets']]
profit_assest_company.sort_values(by=['Profits as % of Assets'],ascending=False).head(10)

The current output which I am getting is:

enter image description here

The desired output which I want is:

enter image description here

Can anyone help me with this?

4
  • You can try print(df.head(10).to_string(index=False)) Commented Apr 18, 2021 at 1:11
  • Where are you displaying the data? A jupyter notebook or somewhere else? Commented Apr 18, 2021 at 1:32
  • @EricTruett I am trying to display in Jupyter notebook itself. Commented Apr 18, 2021 at 14:17
  • @ChihebNexus I don't want to do it with print statement, I did find out how to do with print but i wanted to do it without print statement. Commented Apr 18, 2021 at 14:17

1 Answer 1

1

You can use pandas styling to hide the index in a jupyter notebook

(
  profit_assest_company
  .sort_values(by=['Profits as % of Assets'], ascending=False)
  .head(10)
).style.hide_index()
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.