2

I need to divide data in an excel and put it into another excel using python

For Example, suppose i have an excel which has 1000 rows of data as follows

Name    Number

name1   number1
name2   number2
name3   number3

and so on

Now suppose there are 1000 rows and i need to select 200 rows at a time and put those values in another excel and then remove these 200 values from this excel and then take the next 200 values and put it into another excel How can i do it using python

2 Answers 2

3

You can achieve it using pandas library:

import pandas as pd    
dfs = pd.read_excel(file_name, sheetname=None)

#divide
df1=dfs[:200]
df2=dfs[200:400] and so on...

#saving divided dataframes to different excels
df1.to_excel("df1.xlsx")

Hope it helps.

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

2 Comments

but what if i don't know how many rows are there and i need to find the last row and then divide accordingly?
@GavyaMehta you can use len(dfs) or len(df.index) to count the rows
0
  1. pip install pandas.
  2. Convert excel file to data-frame using pandas.
  3. Then Slice the data-fame to 200 using simple python slicing method [:200]
  4. now write the data-frame to new excel file
  5. Again slice the old excel data-frame to ignore first 200 records.

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.