I have the following Pandas data frame:
import pandas as pd
df = pd.DataFrame({'d': [1, 2, 3]}, index=['FOO', 'BAR', 'BAZ'])
df
d
FOO 1
BAR 2
BAZ 3
What I want to do is to append two strings in front of the index.
str1 = "x"
str2 = "y"
Yielding:
d
x_y.FOO 1
x_y.BAR 2
x_y.BAZ 3
How can I do that?
df.index="x_y."+df.indexordf.index=str1+'_'+str2+df.index?df.index=f"{str1}_{str2}."+df.index