Aggregating data every n elements
Nobody has claimed this yet.
Assessment
- Difficulty
- 5/5
- Estimated time
- Over a week
- Newbie friendliness
- 25/100
- Issue type
- Feature
- Clarity
- Needs clarification
- Activity status
- Stale
- Tech stack
- pandas, python
- Domain
- data, stream-processing
Research direction
Start with the reported stream.map(...).partition(100).to_batch().map_partitions(func) chain and inspect the map_partitions entry point, especially how its example is inferred. Determine whether chunked pandas value_counts aggregation is supported or requires a new API, then define a reproducible example and tests that establish the expected output for successive 100-element batches.
Written by the indexing model from the issue text.
Description
Hi,
I would like to calculate the .value_counts() from a pandas dataframe in chunks of n elements and output the aggregated result.
For example, I have 1000 elements. Calculate the value_counts() for the first 100 and output the result, aggregate the result to the next 100 elements and output it again.
I tried
def func(df):
return df
stream.map(df["OFFENSE_CODE"]).partition(100).to_batch().map_partitions(func)
but I get
TypeError Traceback (most recent call last)
<ipython-input-291-e68a39a9e8bb> in <module>
1 def func(df):
2 return df
----> 3 stream.map(df["OFFENSE_CODE"]).partition(100).to_batch().map_partitions(func)
4
5 # a.value_counts()
~\Anaconda3\lib\site-packages\streamz\collection.py in map_partitions(func, *args, **kwargs)
19 example = kwargs.pop('example', None)
20 if example is None:
---> 21 example = func(*[getattr(arg, 'example', arg) for arg in args], **kwargs)
22
23 streams = [arg for arg in args if isinstance(arg, Streaming)]
TypeError: func() missing 1 required positional argument: 'df'
BTW I am not sure this is the best approach to do this. Any hint?
- Dominant language
- Python
- Stars
- 1.3k
- Forks
- 149
- PR merge metrics
- No merged PRs in 30d
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from python-streamz/streamz
-
Difficulty 3/5 1-2 days Newbie friendliness 35/100
python-streamz/streamz#481 · 4 comments ·
-
Combining the streamz.Stream.filenames() and streamz.Stream.from_textfile() using dask scatter? Open
Difficulty 5/5 Over a week Newbie friendliness 25/100
python-streamz/streamz#480 · 2 comments ·
-
Difficulty 5/5 Over a week Newbie friendliness 20/100
python-streamz/streamz#479 · 1 comment ·
-
Difficulty 5/5 Over a week Newbie friendliness 20/100
python-streamz/streamz#478 · 6 comments ·
-
Difficulty 4/5 3-5 days Newbie friendliness 10/100
python-streamz/streamz#476 · 17 comments · 2 reactions ·
All issues in python-streamz/streamz
Similar issues
-
Difficulty 2/5 1-3 hours Newbie friendliness 88/100
-
Difficulty 2/5 1-3 hours Newbie friendliness 82/100
-
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
-
enhancement
Difficulty 2/5 1-3 hours Newbie friendliness 72/100
-
Difficulty 2/5 1-3 hours Newbie friendliness 74/100