Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Extract data from DataFrames #33

Merged
merged 20 commits into from
Aug 21, 2024
Merged

Extract data from DataFrames #33

merged 20 commits into from
Aug 21, 2024

Conversation

jakubno
Copy link
Member

@jakubno jakubno commented Jul 30, 2024

Description

MVP for easy way to extract data from pandas DataFrames.

  • This should allow users to get data in a format which is easy to use
  • In python you can transform the data directly in Pandas DataFrame
  • It's accessible as data on the Result object.

Steps to try it out (Python only)

  1. Install E2B e2b-code-interpreter==0.0.11b2
  2. You'll be able to access the df variable in the code through the .data property on the result of the execution. As long as the last line is a dataframe, you'll be able to access it

Here's a code snippet to try this

import asyncio

from e2b_code_interpreter import AsyncCodeInterpreter
from dotenv import load_dotenv

load_dotenv()
CODE = """
import pandas
data = {  
  "food": ["bacon", "pulled pork", "oats"],
  "type": ["meat", "meat", "vegetarian"],
  "calories": [420, 380, 390],
}
df = pd.DataFrame(data)

df
"""

CODE2 = """
df2 = df.groupby(["type"]).agg({'calories': 'mean'})
df2
"""


async def main():
    sandbox = await AsyncCodeInterpreter.create(timeout=180)
    execution = await sandbox.notebook.exec_cell(CODE)
    print(execution.results[0].data)
    # {'food': ['bacon', 'pulled pork', 'oats'], 'type': ['meat', 'meat', 'vegetarian'], 'calories': [420, 380, 390]} 
    execution = await sandbox.notebook.exec_cell(CODE2)
    print(execution.results[0].data)
    # {'calories': [400.0, 390.0]}

    await sandbox.kill()


asyncio.run(main())

@jakubno jakubno added the python-rc Python SDK - Release candidate label Jul 30, 2024
@jakubno jakubno changed the base branch from main to beta July 30, 2024 17:21
@jakubno jakubno added the js-rc JS SDK - Release candidate label Jul 30, 2024
@ValentaTomas ValentaTomas added the feature New feature or request label Aug 1, 2024
@jakubno jakubno marked this pull request as ready for review August 21, 2024 12:57
@jakubno jakubno merged commit cfc3207 into beta Aug 21, 2024
@ValentaTomas ValentaTomas deleted the beta-df branch August 21, 2024 17:26
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature New feature or request js-rc JS SDK - Release candidate python-rc Python SDK - Release candidate
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants