Skip to main content

Read all csv files in a directory with one iterator.

Project description

A Python package used to iterate through a directory of csv files and read each row as a dict.

Install

pip install csvdir

Examples

>>> import csvdir

>>> reader = csvdir.read_dir('data/')
>>> reader.names
['people1', 'people2']
>>> reader.paths
['data/people1.csv', 'data/people2.csv']

>>> for row in reader:
...    print(row)
...
{'id': '1', 'name': 'Odos', 'age': '38'},
{'id': '2', 'name': 'Kayla', 'age': '31'},
{'id': '3', 'name': 'Dexter', 'age': 'two'},
{'id': '4', 'name': 'Joe', 'age': '44'},
{'id': '5', 'name': 'James', 'age': '55'},
{'id': '6', 'name': 'Luke', 'age': '0'}

>>> for name, row in reader.with_names():
...    print(name, row)
...
'people1' {'id': '1', 'name': 'Odos', 'age': '38'},
'people1' {'id': '2', 'name': 'Kayla', 'age': '31'},
'people1' {'id': '3', 'name': 'Dexter', 'age': 'two'},
'people2' {'id': '4', 'name': 'Joe', 'age': '44'},
'people2' {'id': '5', 'name': 'James', 'age': '55'},
'people2' {'id': '6', 'name': 'Luke', 'age': '0'}

>>> for path, row in reader.with_paths():
...    print(path, row)
...
'data/people1.csv' {'id': '1', 'name': 'Odos', 'age': '38'},
'data/people1.csv' {'id': '2', 'name': 'Kayla', 'age': '31'},
'data/people1.csv' {'id': '3', 'name': 'Dexter', 'age': 'two'},
'data/people2.csv' {'id': '4', 'name': 'Joe', 'age': '44'},
'data/people2.csv' {'id': '5', 'name': 'James', 'age': '55'},
'data/people2.csv' {'id': '6', 'name': 'Luke', 'age': '0'}

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distributions

No source distribution files available for this release.See tutorial on generating distribution archives.

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

csvdir-0.5.0-py3-none-any.whl (31.3 kB view details)

Uploaded Python 3

File details

Details for the file csvdir-0.5.0-py3-none-any.whl.

File metadata

  • Download URL: csvdir-0.5.0-py3-none-any.whl
  • Upload date:
  • Size: 31.3 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.0.1 CPython/3.13.0

File hashes

Hashes for csvdir-0.5.0-py3-none-any.whl
Algorithm Hash digest
SHA256 338fb2a2e1bf82e02bb9f9656ac6cd9dd01a5e1520ed7c5e910d44e5d682aca7
MD5 78435171619445ca7dee4cadba12eec9
BLAKE2b-256 73d86ff1cb786116fc8c8a7b0570eee0dbc257a0d9a9d3a1d40fdbf6b9c38389

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page