0

I am reading a CSV file in Python.

So, how can I use "str.split(...)" to count the rows, columns number of the data? Then, how can I find the length of the contents as a string?

I can not use Pandas or Numpy libraries.

Thank you for your help.

What I got so far:

with open(file,"r") as f:
    reader = csv.reader(f,delimiter=',')
    data = list(reader)
    row_count = len(data)

print(row_count)

But it does not use by split() method. I'm still stuck with the columns.

congdanh1594
  • 67
  • 1
  • 7
  • What have you tried so far? – ddejohn Feb 14 '21 at 03:07
  • 1
    Here you go: [Number of columns](https://stackoverflow.com/questions/11310248/find-number-of-columns-in-csv-file), [Number of rows](https://stackoverflow.com/questions/27504056/row-count-in-a-csv-file) and [Length of contents](https://stackoverflow.com/questions/36291944/how-to-get-length-of-each-string-in-a-csv-row-then-use-that-in-formating-number). Btw this is research that could've been done prior to asking. – costaparas Feb 14 '21 at 03:14
  • Does this answer your question? [Python 3 Count number of rows in a CSV](https://stackoverflow.com/questions/56436024/python-3-count-number-of-rows-in-a-csv) – ddejohn Feb 14 '21 at 03:16
  • `column_count = len(data[0])` – costaparas Feb 14 '21 at 03:25

0 Answers0