I have a dataframe as follows:
Original dataframe:
| Index | Value | |
|---|---|---|
| 0 | aT | 1 |
| 1 | bee | 2 |
| 2 | cT | 3 |
| 3 | Y | 4 |
| 4 | D | 5 |
I would like to combine each item in the "index" column (except items trailing with T), hyphen (-) and row number like this:
Expected result:
| Index | Value | |
|---|---|---|
| 0 | aT | 1 |
| 1 | bee-1 | 2 |
| 2 | cT | 3 |
| 3 | Y-3 | 4 |
| 4 | D-4 | 5 |
My code is the following:
df = pandas.DataFrame({"Index": ["aT", "bee", "cT","Y","D"], "Value": [1, 2, 3,4,5]})
ind_name = df.iloc[df.index,0].apply(lambda x: x + '-' + str(df.index) if "T" not in x else x)
How to correct my code?