Trying to create a function to specify the name of a DataFrame, so it can be used within another function. Tried a few different approaches, but this is a simplified version of what I have now.
import pandas as pd
data1 = {'var1': [1, 2, 3], 'var2': [1, 2, 3]}
h_df1 = pd.DataFrame(data1)
def hh(wave):
hh = 'h_' + wave
return hh
def table(wave):
hh_data = hh(wave)
hh_data["new_var"] = hh_data["var1"]*hh_data["var2"]
return table
table = table("df1")
print(table)
This gives the error: TypeError: string indices must be integers
The result I am expecting is that hh_data uses a DataFrame named h_df1. Looking for a way to automate which DataFrame is picked up. It's part of a more complex system.