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.4.0-py3-none-any.whl (24.8 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: csvdir-0.4.0-py3-none-any.whl
  • Upload date:
  • Size: 24.8 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.4.0-py3-none-any.whl
Algorithm Hash digest
SHA256 6df8d76b5637226250808b777a8c2de60d2b7376b32df40800a82da7b40ab570
MD5 9ee14c725712c2aef2a56cccc0d09863
BLAKE2b-256 cfee8325d1f4ce0756ec824e92bd05204924579e22089826d49f4c83f0da3030

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