1

I am attempting to extract the name of a data frame as a string, in order to check it for a pattern. I am using python 3.7.

To clarify, I am doing this for a function which check if a string "Vol" is in the name (the title) of the data frame, and performs certain operations if it is.

def customize_df(in_df,out_df,old_col_val,new_col_val):
out_df = in_df.copy()
out_df_name = str(out_df)    
if 'Vol' in out_df_name:
    df_raw = out_df.copy()
    df_raw.columns = df_raw.columns.str.replace(r"_Vol", "_Vol_Raw")
    df_raw = pd.DataFrame(data = df_raw, columns= df_raw.columns)

So, if I input "data_Vol" in the first variable of the function, I would want it to go through the if statement.

This outputs the contents of the data frame, not the name.

I have also tried using, out_df_name.name, which generates the same result.

arkadiy
  • 746
  • 1
  • 10
  • 26

0 Answers0