0

I have a pandas data frame with multiple filenames, like so

filename
a.csv
b.csv
c.csv

I want to find the size of these files and store the result in a newly created 'size' column, i.e.

filename size
a.csv    1KB
b.csv    10KB
c.csv    220KB

I did the following

  1. df['size'] = os.stat(df['filename']).st_size
  2. df['size'] = os.path.getsize(df['filename'])

but both of them are throwing the error stat: path should be string, bytes, os.PathLike or integer, not Series.

P.S. While I am not averse to creating another list and then, finding the size, I feel that that method would be extremely time-consuming. Is there a simple way of achieving what I want?

Nilima
  • 169
  • 1
  • 8

0 Answers0