1

I have a shared spreadsheet that gets rows added to it everyday. I am creating a script that reads the spreadsheet into a dataframe pd.read_excel(infile, sheet_name=0) and checks for duplicate rows using df.drop_duplicates(keep='first'). The script is going to be be an installed package on multiple people's computer for them to use at any time and different people will want to check different rows. Is there a way to have whoever wants to use the script choose the range of rows they want to check? For example, if the spreadsheet has 100 rows, and someone wants to check for duplicate rows in rows 40-60, is it possible to do this?

1
  • Yes, you want .iloc. For example, my_df = df.iloc[40:60,:] Commented Dec 17, 2018 at 16:17

1 Answer 1

1

You can accept user inputs for the row bounds and then pass them to iloc:

import pandas as pd

start = int(input('Enter your starting row: '))
stop = int(input('Enter your ending row: '))

df_limited = df.iloc[start:stop].drop_duplicates(keep='first')
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.