I have the following Python code that reads a CSV file as a multi-index Pandas…
- User
I have the following Python code that reads a CSV file as a multi-index Pandas DataFrame, calculates statistics, and reorders its contents for JSON output:
from pandas import read_csv import json import pandas df = read_csv("input.csv", header=[0, 1, 2, 3], index_col=[0]) across_steps = df.stack([1, 2, 3]) mean = across_steps.mean(axis=1).unstack([1, 2, 3]) std = across_steps.std(axis=1).unstack([1, 2, 3]) min = across_steps.min(axis=1).unstack([1, 2, 3]) max = across_steps.max(axis=1).unstack([1, 2, 3]) ret = { "mean": {}, "std": {}, "min": {}, "max": {}, } for l1 in df.columns.get_level_values(1).unique(): ret["mean"][l1] = {} ret["std"][l1] = {} ret["min"][l1] = {} ret["max"][l1] = {} for l2 in df.columns.get_level_values(2).unique(): if l2 not in mean[l1]: continue ret["mean"][l1][l2] = {} ret["std"][l1][l2] = {} ret["min"][l1][l2] = {} ret["max"][l1][l2] = {} for l3 in df.columns.get_level_values(3).unique(): if l3 not in mean[l1][l2]: continue ret["mean"][l1][l2][l3] = json.loads( mean[l1][l2][l3].to_json(orient="values") ) ret["std"][l1][l2][l3] = json.loads( std[l1][l2][l3].to_json(orient="values") ) ret["min"][l1][l2][l3] = json.loads( min[l1][l2][l3].to_json(orient="values") ) ret["max"][l1][l2][l3] = json.loads( max[l1][l2][l3].to_json(orient="values") )
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.