I have .csv files (abc.csv, def.csv, etc...) in the directory and I would like to count of rows in every file and save the single file having name column and count column. My expected output as below :
df = name count
abc ....
def ....
ghi ....
I am doing something like below to get count but not able to covert in dataframe. Please suggest.
import os
path = '/some/path/to/file'
for filename in os.listdir(path):
with open(filename, 'r', encoding="latin-1") as fileObj:
# -1 to exclude the header
print("Rows Counted {} in the csv {}:".format(len(fileObj.readlines()) - 1, filename))