Let's supposed I have a dataframe:
df = quandl.get("FRED/DEXBZUS")
The output would be:
print(df)
    Year    Value
1995-01-02  0.8440
1995-01-03  0.8450
1995-01-04  0.8450
1995-01-05  0.8430
1995-01-06  0.8400
1995-01-09  0.8440
1995-01-10  0.8470
1995-01-11  0.8510
I am trying to create a new column, filled by the variable name:
print(df)
    Year     Value  Variable
1995-01-02  0.8440    df
1995-01-03  0.8450    df
1995-01-04  0.8450    df
1995-01-05  0.8430    df
1995-01-06  0.8400    df
1995-01-09  0.8440    df
1995-01-10  0.8470    df
1995-01-11  0.8510    df
I would like to do this, in a loop process, using two differents dataframes:
df = quandl.get("FRED/DEXBZUS")
df2 = quandl.get("FRED/DEXBZUS")
data = [df, df2]
for i in data:
dps = []
for i in df:
        d = i.reset_index()
        d = pd.DataFrame(d)
        d['variable'] = [i]
But I didn't get the variables name inside the columns.
It should be like this :
    Year     Value  Variable
1995-01-02  0.8440    df
1995-01-03  0.8450    df
1995-01-04  0.8450    df
1995-01-05  0.8430    df
1995-01-06  0.8400    df
1995-01-09  0.8440    df
1995-01-10  0.8470    df
1995-01-11  0.8510    df
2008-01-02  0.8440    df2
2008-01-03  0.8450    df2
2008-01-04  0.8450    df2
2008-01-05  0.8430    df2
2008-01-06  0.8400    df2
2008-01-09  0.8440    df2
2008-01-10  0.8470    df2
2008-01-11  0.8510    df2
 
     
    