Spaces:
Runtime error
Runtime error
| import io | |
| import sys | |
| import contextlib | |
| async def run_pandas_script(pandas_script , df) : | |
| captured_output = None | |
| string_io = io.StringIO() | |
| try : | |
| with contextlib.redirect_stdout(string_io) : exec(pandas_script , {'df' : df}) | |
| captured_output = string_io.getvalue() | |
| except Exception as e : | |
| print(f'Error executing the generated script:\n{e}') | |
| captured_output = f'Error: {e}' | |
| finally : string_io.close() | |
| print(captured_output) | |
| return captured_output |