Skip to content

Instantly share code, notes, and snippets.

@neeraj9
Created March 28, 2018 06:39
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 neeraj9/7ea658e181704ace52cf0da357ad9b6d to your computer and use it in GitHub Desktop.
Save neeraj9/7ea658e181704ace52cf0da357ad9b6d to your computer and use it in GitHub Desktop.
BeamPartile - 10 minutes to pandas, so lets have some fun
#!python
# @doc 10 minutes to pandas, so lets have some fun
#
# py_10_min_to_pandas
#
# see https://pandas.pydata.org/pandas-docs/stable/10min.html
# see https://gist.github.com/neeraj9/970e73412a893ddaed7be31e84199c29
#
# Dependencies:
#
# sudo pip3 install pandas numpy matplotlib
#
# run py_10_min_to_pandas(<<"{}">>, <<>>)
#
# Author: Neeraj Sharma
import pandas as pd
import numpy as np
import matplotlib.pyplot as plt
import json
import sys
import traceback
def process(json):
series_data = json['data']
s = pd.Series(series_data)
return "todo"
# ---------------------------------------------------------------------
# Generic function required by BeamParticle to invoke this python
# function and ensure that this is also available as an HTTP endpoint
# ---------------------------------------------------------------------
from Pyrlang import term
def main(data_binary, context_binary):
data = data_binary.bytes_.decode('utf-8')
context = context_binary.bytes_.decode('utf-8')
result = handle_event(data, context)
return term.Binary(result.encode('utf-8'))
def handle_event(data, context):
try:
json_value = json.loads(data)
json_response = process(json_value)
return json.dumps(json_response)
except Exception as e:
sys.stderr.write('Sample log message on stderr. Received message={}\n'.format(e))
traceback_lines = traceback.format_exception(None, e, e.__traceback__)
print(''.join(traceback_lines),
file=sys.stderr, flush=True)
return str(e)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment