0

I want to be able to choose which rows I want to display when I print data from an excel sheet

data = pd.read_excel("TABLE.xlsx", usecols='D,E,F')

This allows me to choose which columns I want to display, what do I need to add to choose the specific rows?

Bas H
  • 2,114
  • 10
  • 14
  • 23
Jay
  • 1

1 Answers1

0
# Below code only shows rows where the column 'D' values are greater than 5

data = pd.read_excel("TABLE.xlsx", usecols='D,E,F')
selected_rows = data[data['D'] > 5]

This is for selecting from D column.Similarly, use other indexing based on your requirement.

You can also use other boolean operators (<, >=, <=, ==, !=, etc.) to select rows based on different criteria, and combine multiple conditions using logical operators (& , | , ~ ).

Check this link for more help about boolean indexing Logical operators for Boolean indexing in Pandas

Thierry Lathuille
  • 23,663
  • 10
  • 44
  • 50