File size: 688 Bytes
ceb3ae8
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
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