I'm running a couple of simulations for a number of case studies and the results are stored in a csv file in this
/ Var1 Var2 Var3
0 x x x
1 x x x
2 x x x
3 x x x
0 x x x
1 x x x
2 x x x
What i'm trying to do is substitute the first column (which is the index for the simulation numbar for each case) with the case name. What I want to do is for the csv to read like this:
/ Var1 Var2 Var3
Case1 x x x
Case1 x x x
Case1 x x x
Case1 x x x
Case2 x x x
Case2 x x x
Case2 x x x
I've thought of adding a condition where if the number in the first column is 0 the substitute it with case, when the next 0 is found then continue with case+1 (i've got the case names in a vector)
My issue is that I don't know how to access the values in the first row and evaluate them, and subsequently substitute them. I'd imagine pandas must have a convenient way of doing something like this
df.groupby(index).cumcount(). pandas.pydata.org/pandas-docs/stable/generated/…df.iloc[2, 0]will for example access the first element of the third line if this is what you are looking for.new_index = df.index.values, change whatever you want in this list, and then replace the old index column like this:df.index = new_index