Skip to content

Instantly share code, notes, and snippets.

@zeryx
Created March 19, 2021 16:45
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 zeryx/0a5d7f66484f5e3c4e2977616474baa6 to your computer and use it in GitHub Desktop.
Save zeryx/0a5d7f66484f5e3c4e2977616474baa6 to your computer and use it in GitHub Desktop.
algorithm api calls with large pandas dataframe objects, example of using the data API
import Algorithmia
import pandas as pd
client = Algorithmia.client()
def apply(input):
input_dataframe = pd.DataFrame.from_dict(client.file(input).getJson())
...
...
output_dataframe = pd.Dateframe(...)
output_dict = output_dataframe.to_dict()
output_data_path = "data://.algo/username/algoname/temp/somefile.json"
client.file(output_data_path).putJson(output_dict)
return output_data_path
import Algorithmia
import pandas as pd
client = Algorithmia.client(api_key="YOUR_API_KEY_HERE", api_address="PATH_TO_YOUR_CLUSTER")
algo = client.algo("algo://username/algoname/latest")
some_collection = "data://.my/collection"
input_data = pd.Dataframe(..).to_dict()
filename = "input.json"
remote_file_path = f"{some_collection}/{filename}"
client.file(remote_file_path).putJson(input_data)
result = algo.pipe(remote_file_path)
output_data = pd.Dataframe.from_dict(client.file(result).getJson())
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment