Spaces:
Sleeping
Sleeping
import pandas as pd | |
def load_excel(file): | |
df = pd.read_excel(file) | |
return file, df | |
def run_code(file, code): | |
scope = {'pd': pd} | |
if file: | |
print('file ok') | |
df = pd.read_excel(file) | |
scope['df'] = df | |
exec(code, scope, scope) | |
print(scope.keys()) | |
if not 'new_df' in scope: | |
print("new_df not defined") | |
scope['new_df'] = df.copy() | |
new_df = scope['new_df'] | |
return new_df | |
else: | |
print(f"No file provided") | |
df = pd.DataFrame() | |
return df | |
def export_df(df, filename): | |
filename = filename.replace('.xlsx', '_coded.xlsx') | |
df.to_excel(filename, index=False) | |
return filename | |