Question: I have a data frame like below:

```
    type            value
0   typea_amount    1
1   typea_money     2
2   typeb_amount    3
3   typeb_money     4
4   typec_amount    5
5   typec_money     6

```

How can I change this data frame to below:

```
    type            amount         money
0   typea           1              2
1   typeb           3              4
2   typec           5              6

```

Here is the create data frame:

```
pd.DataFrame.from_dict({'type': ['typea_amount', 'typea_money', 'typeb_amount', 'typeb_money', 'typec_amount', 'typec_money'], 'value': [1, 2, 3, 4, 5, 6]})

```

Thanks!

Answer: 
```
res = (df
        #extract amount and money into a separate column
       .assign(category = df['type'].str.split('_').str[-1],
               type = df['type'].str.split('_').str[0]
              )
        #pivot table and clean up a bit
       .pivot('type','category','value')
       .reset_index()
       .rename_axis(columns=None)
      )

res

    type    amount  money
0   typea     1       2
1   typeb     3       4
2   typec     5       6

```
One way of doing it

```
df_amt = df[df.type.str.contains('amount')].rename(columns={"value": "amount"})
df_amt['type'] = df_amt['type'].apply(lambda x: x.split('_')[0])
df_mny = df[df.type.str.contains('money')].rename(columns={"value": "money"})
df_mny['type'] = df_mny['type'].apply(lambda x: x.split('_')[0])
df_amt.merge(df_mny, on = 'type' )

```

**Output**

```
    type    amount  money
0   typea   1       2
1   typeb   3       4
2   typec   5       6

```