0

I have an excel file with more than 1 million rows. Now i need to split that for every n rows and save it in a new file. am very new to python. Any help, is much appreciated and needed

3
  • Save your excel document as a csv and read the csv module documentation docs.python.org/2/library/csv.html. Commented Jun 4, 2015 at 10:16
  • Hope this api helps openpyxl.readthedocs.org/en/latest Commented Jun 4, 2015 at 10:33
  • I have already tried that, the excel files are so large that while trying to convert them into csv file they get struck for long time.that is why am trying to split excel sheet into smaller multiple excels so that i can convert them into csv and read them into mysql using python Commented Jun 4, 2015 at 11:23

1 Answer 1

1

As suggested by OhAuth you can save the Excel document to a csv file. That would be a good start to begin the processing of you data.

Processing your data you can use the Python csv library. That would not require any installation since it comes with Python automatically.

If you want something more "powerful" you might want to look into Pandas. However, that requires an installation of the module.

If you do not want to use the csv module of Python nor the pandas module because you do not want to read into the docs, you could also do something like.

f = open("myCSVfile", "r")
for row in f:
    singleRow = row.split(",") #replace the "," with the delimiter you chose to seperate your columns
    print singleRow
    > [value1, value2, value3, ...] #it returns a list and list comprehension is well documented and easy to understand, thus, further processing wont be difficult

However, I strongly recommend looking into the moduls since they handle csv data better, more efficient and on 'the long shot' save you time and trouble.

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

4 Comments

I have already tried that, the excel files are so large that while trying to convert them into csv file they get struck for long time.that is why am trying to split excel sheet into smaller multiple excels so that i can convert them into csv and read them into mysql using python
@SailendraVarma If you just want to create for each row a new file, there is no need to take the detour over mysql. You can do that from the csv file! If you have problems converting the Excel into csv, look into the modul JLILI posted. But making a csv, reading it into mysql and then reading it out of mysql to create a file for n rows does not makes sense...
u didn't get my requirement.I don't need to split excel for every row and create a new excel file for that.Will defntly look into the csv module
@SailendraVarma Sorry. You might want to edit your question then. If you like the hints, please upvote or accept answere :)

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.