Skip to main content

A fast and memory efficient way to load large CSV files (Timeseries data) into Pandas

Project description

fast_csv_loader.py

The csv_loader function efficiently loads a partial portion of a large CSV file containing time-series data into a pandas DataFrame.

The function allows:

  • Loading the last N lines from the end of the file.
  • Loading the last N lines from a specific date.

It can load any type of time-series (both timezone aware and Naive) and daily or intraday data.

It is useful for loading large datasets that may not fit entirely into memory. It also improves program execution time, when iterating or loading a large number of CSV files.

Supports Python >= 3.8

Install

pip install fast-csv-loader

Documentation

https://bennythadikaran.github.io/fast_csv_loader/

Performance

Loading a portion of a large file is significantly faster than loading the entire file in memory. Files used in the test were not particularly large. You may need to tweak the chunk_size parameter for your use case.

It is slower for smaller files or if you're loading nearly the entire portion of the file.

I chose a 6Kb chunk size based on testing with my specific requirements. Your requirements may differ.

csv_loader vs pandas.read_csv

Execution time - Last 160 lines

Execution time - Last 160 lines upto 1st Jan 2023

To run this performance test.

py tests/run.py

At the minimum, the CSV file must contain a Date and another column with newline chars at the end to correctly parse and load.

Date,Price\n
2023-12-01,200\n

Unit Test

To run the test:

py tests/test_csv_loader.py

Project details


Download files

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

Source Distribution

fast_csv_loader-2.0.0.tar.gz (17.1 kB view details)

Uploaded Source

Built Distribution

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

fast_csv_loader-2.0.0-py3-none-any.whl (16.9 kB view details)

Uploaded Python 3

File details

Details for the file fast_csv_loader-2.0.0.tar.gz.

File metadata

  • Download URL: fast_csv_loader-2.0.0.tar.gz
  • Upload date:
  • Size: 17.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.12.9

File hashes

Hashes for fast_csv_loader-2.0.0.tar.gz
Algorithm Hash digest
SHA256 8ea07500175a1faeaca960560c1408b84bc7616405385a5da6262f7377258e1b
MD5 03b86014dace6e339da96722a55dd898
BLAKE2b-256 9e7254166c327288fed91e0c52bf0ec8300fa1bdfce391ee19e5eedffc3a4142

See more details on using hashes here.

Provenance

The following attestation bundles were made for fast_csv_loader-2.0.0.tar.gz:

Publisher: publish-to-pypi.yml on BennyThadikaran/fast_csv_loader

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file fast_csv_loader-2.0.0-py3-none-any.whl.

File metadata

File hashes

Hashes for fast_csv_loader-2.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 dd729cb71b7e739bd2bd49f3bf14cf26b9c714affa30a6466f85c89cf757359c
MD5 06c4629ccf3fa86817cff845da42d1da
BLAKE2b-256 c9fbb362b6bd14654acfc28c95797a561928c3e5c004b073cbedc393c6195a01

See more details on using hashes here.

Provenance

The following attestation bundles were made for fast_csv_loader-2.0.0-py3-none-any.whl:

Publisher: publish-to-pypi.yml on BennyThadikaran/fast_csv_loader

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

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