'python csv to xlsx split file excel

I need to convert large csv file to xlsx file, about 5 million rows, I need to set each output xlsx file to 100,000 lines and save it separately

import pandas as pd

data = pd.read_csv("k.csv")

data.to_excel("new_file.xlsx", index=None, header=True)

how should i add the row count parameter?



Solution 1:[1]

Use iloc to slice the csv as many times as needed.

e.g., to get rows 10000 to 19999, you would use

subset = data.iloc[10000:20000]

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 2ps