myimagelib.myImageLib.readdata

myimagelib.myImageLib.readdata(folder, ext='csv', mode='i')

Read all files in a folder with certain extension. Instead of returning a list of directories as dirrec() does, readdata() puts the file names and corresponding full directories in a pandas.DataFrame. The table will be sorted by the file names (strings), so the order would likely be correct. In the worst case, it is still easier to resort the pandas.DataFrame, compared to the list of strings returned by dirrec().

Parameters:
  • folder (str) – the folder to read files from.

  • ext (str) – optional param, default to "csv", specifies the extension of files to be read.

  • mode (str) – "i" for immediate, "r" for recursive. Default to "i"

Returns:

a 2-column pandas.DataFrame table containing file names "Name" and the corresponding full directories "Dir".

Return type:

pandas.DataFrame

>>> from myimagelib import readdata
>>> readdata("path/to/folder", ext="csv")
>>> readdata("path/to/folder", ext="csv", mode="r")

Edit

  • Nov 15, 2022 – Add mode optional argument, to specify whether to read data only in the immediate folder, or read recursively.