I have a CSV file containing 200 lines. I want to create a function to read every 50 lines together and then store these (50 lines) in a .txt file until the csv file ends. How can I do that please? Any help appreciated.
import pandas as pd
import csv
def my_function(n):
dataset = pd.read_csv('e.csv', nrows=50)
X = dataset.iloc[:,[0,0]].values
Update::
def my_function(n):
dataset = pd.read_csv('e.csv', nrows=n)
X = dataset.iloc[:,[0,0]].values
with open('funct.txt', 'w') as file:
for i in X:
file.write("{}\n".format(i))
return
row_count = len(open("e.csv").readlines())
print(row_count)
n=50
my_function(n)
Now my problem how can read each 50 lines after another in each time until reach to the maximum length (200)?