Created
March 19, 2021 16:45
-
-
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
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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