def percentage(<EOL>df,<EOL>column: str,<EOL>group_cols: Union[str, List[str]] = None,<EOL>new_column: str = None<EOL>):
new_column = new_column or column<EOL>if group_cols is None:<EOL><INDENT>df[new_column] = <NUM_LIT> * df[column] / sum(df[column])<EOL><DEDENT>else:<EOL><INDENT>df[new_column] = <NUM_LIT> * df[column] / df.groupby(group_cols)[column].transform(sum)<EOL><DEDENT>return df<EOL>
Add a column to the dataframe according to the groupby logic on group_cols

---

### Parameters

*mandatory :*
- `column` (*str*): name of the desired column you need percentage on

*optional :*
- `group_cols` (*list*): names of columns for the groupby logic
- `new_column` (*str*): name of the output column. By default `column` will be overwritten.

---

**Input**

| gender |    sport   | number |
|:------:|:----------:|:------:|
|  male  |   bicycle  |   17   |
| female | basketball |   17   |
|  male  | basketball |    3   |
| female |  football  |    7   |
| female |   running  |   30   |
|  male  |   running  |   20   |
|  male  |  football  |   21   |
| female |   bicycle  |   17   |

```cson
percentage:
  new_column: 'number_percentage'
  column: 'number'
  group_cols: ['sport']
```

**Output**

| gender |    sport   | number | number_percentage |
|:------:|:----------:|:------:|:-----------------:|
|  male  |   bicycle  |   17   |        50.0       |
| female | basketball |   17   |        85.0       |
|  male  | basketball |    3   |        15.0       |
| female |  football  |    7   |        25.0       |
| female |   running  |   30   |        60.0       |
|  male  |   running  |   20   |        40.0       |
|  male  |  football  |   21   |        75.0       |
| female |   bicycle  |   17   |        50.0       |