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
-
Save your excel document as a csv and read the csv module documentation docs.python.org/2/library/csv.html.thodic– thodic2015-06-04 10:16:43 +00:00Commented Jun 4, 2015 at 10:16
-
Hope this api helps openpyxl.readthedocs.org/en/latestAmen Jlili– Amen Jlili2015-06-04 10:33:29 +00:00Commented 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 pythonSailendra Varma– Sailendra Varma2015-06-04 11:23:14 +00:00Commented Jun 4, 2015 at 11:23
1 Answer
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.