e2b-dev / e2b-dev/code-interpreter

Missing DataFrame index in `Result.data`

オープン
#88 コメント 4 件 リアクション 0 件 担当者 1 名 GitHub で見る

@jakubno がすでに取り組んでいます。

2025年4月23日 から。

bug Code Interpreter
主要言語
Python
スター
2.4k
フォーク
228
平均マージ
48分
マージ済み PR(30日)
5

説明

When a DataFrame is displayed, the corresponding Result has the data attribute in the format {column -> [values]} (equivalent to df.to_dict(orient="list")). This means that we lose the table index, which can be relevant. Is it possible to use a format that preserves this information?

To keep consistency with pandas' to_dict, any of these options would work:

  • 'dict' (default) : dict like {column -> {index -> value}}
  • 'split' : dict like {'index' -> [index], 'columns' -> [columns], 'data' -> [values]}
  • 'tight' : dict like {'index' -> [index], 'columns' -> [columns], 'data' -> [values], 'index_names' -> [index.names], 'column_names' -> [column.names]}
  • 'index' : dict like {index -> {column -> value}}

(Note: 'tight' is the only option that preserves the full information, including the index name)

Example
from e2b_code_interpreter import Sandbox

code = """
import pandas as pd
df = pd.DataFrame({"key": ["a", "b", "a", "b"], "value": [1, 2, 3, 4]})
display(df.groupby("key").sum())
"""
with Sandbox() as sandbox:
    execution = sandbox.run_code(code)

result = execution.results[0]
print("Text:")
print(result.text)
print("Data:")
print(result.data)
Text:
     value
key       
a        4
b        6
Data:
{'value': [4, 6]}

Expected (one of the options):

Data:
{'index': ['a', 'b'], 'columns': ['value'], 'data': [[4], [6]], 'index_names': ['key'], 'column_names': [None]}

コントリビューションガイド

このリポジトリのコントリビューションガイドは索引されていません

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

評価

この issue はまだ評価されていません。

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。