Customer purchases large dataset processing pipeline
Project description
# Basic chunked reading
import pandas as pd
chunksize = 100_000
reader = pd.read_csv('huge_orders.csv', chunksize=chunksize)
for chunk in reader:
print(f"Chunk shape: {chunk.shape}")
# feltered_chunks = []
total_sales = 0
for chunk in pd.read_csv('huge_orders.csv', chunksize=100_000):
chunk['total'] = chunk['quantity'] * chunk['price']
total_sales += chunk['total'].sum()
print(total_sales)
# Filter and save to file
filtered_chunks = []
for chunk in pd.read_csv('huge_orders.csv', chunksize=100_000):
filtered = chunk[chunk['country'] == 'USA']
filtered_chunks.append(filtered)
## Combine and save
pd.concat(filtered_chunks)to_csv('usa_orders.csv', index=False)
# Unique value counting across chunks
uni_customers = set()
for chunk in pd.read_csv('huge_orders.csv', chunksize=100_000):
unique_customers.update(chunk['customer_id'].unique())
print(len(unique_custormers))
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
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file customer_purchases_final-1.0.0.tar.gz.
File metadata
- Download URL: customer_purchases_final-1.0.0.tar.gz
- Upload date:
- Size: 3.1 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/2.1.3 CPython/3.12.3 Linux/6.14.0-27-generic
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
ac55ffe344b090ffe3b6be297fa3539a03ed45837bb199056f8babfda644c73f
|
|
| MD5 |
ba5a20c6b83e64b3dafcedd086108bc2
|
|
| BLAKE2b-256 |
b5730032fa1e4e3081e2064b2d44f13665a293bdd5e3c9ee8934f71ec1c80e43
|
File details
Details for the file customer_purchases_final-1.0.0-py3-none-any.whl.
File metadata
- Download URL: customer_purchases_final-1.0.0-py3-none-any.whl
- Upload date:
- Size: 5.4 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/2.1.3 CPython/3.12.3 Linux/6.14.0-27-generic
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
9b67de8d188e233a70bd55a58f41b2f20b4b89a067b63cc61cc6db34d204c51b
|
|
| MD5 |
7451d8493a4b140e5bdf1045ccbf5a02
|
|
| BLAKE2b-256 |
cc03a8890b917aa2346434e97b9fb0de7e7047ba2220217abbda849b2584f8a4
|