A fast and memory efficient way to load large CSV files (Timeseries data) into Pandas
Project description
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 csv_loader
Documentation
https://bennythadikaran.github.io/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
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
run.py
measures the execution time of csv_loader vs. loading the entire file in Pandas DataFrame.
Unit Test
test_csv_loader.py
is the unit test file.
To run the test:
py src/tests/test_csv_loader.py
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Hashes for fast_csv_loader-1.0.0.post1.tar.gz
Algorithm | Hash digest | |
---|---|---|
SHA256 | d2be74557efaff3ccb4cb6b6ea843728789a4798c01fab9a8736d38dc279d0ea |
|
MD5 | b36283ad0cfb598c8da854f3ec46fdaa |
|
BLAKE2b-256 | eb29f0193357798a92bb5102d711f89140848c6254e7af09c58cde2e25dc87e0 |
Hashes for fast_csv_loader-1.0.0.post1-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | ca41e473cdc7403a667820baa974ecfa41d2ca8343d518a19c4dda2952cee956 |
|
MD5 | 56cd0af7174d0e6050165999572b347e |
|
BLAKE2b-256 | 9ee4f7f885e8014f845fdedd30350de9b80707f711f2eb504b2f52c426d097c8 |