Skip to content

Instantly share code, notes, and snippets.

@merlin-quix
Last active January 23, 2023 07:21
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save merlin-quix/ed14aa9cde3d3a69dfce20fe3ead7afb to your computer and use it in GitHub Desktop.
Save merlin-quix/ed14aa9cde3d3a69dfce20fe3ead7afb to your computer and use it in GitHub Desktop.
Step 2 in the procedure "Creating a Kafka Consumer" from this article: https://www.quix.io/blog/send-timeseries-data-to-kafka-python/
for message in consumer:
mframe = pd.DataFrame(message.value)
# Multiply the quantity by the price and store in a new "revenue" column
mframe['revenue'] = mframe['Quantity'] * mframe['Price']
# Aggregate the StockCodes in the individual batch by revenue
summary = mframe.groupby('StockCode')['revenue'].sum()
print(summary)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment