Question: I wasted 3 hours searching for the right syntax. How can i get the value of "prop\_id" in javascript.

view -

```
  <input type="hidden" name="prop_id" value="<?=$prop_id_inserted?>">

```

javascript

```
function upload_docu_by_type(prop_id, input, filetype) {
var fd = new FormData();
var fileInputs = $("." + input);

$.each(fileInputs, function (i, fileInput) {
    if (fileInput.files.length > 0) {
        $.each(fileInput.files, function (k, file) {
            fd.append('images[]', file);
        });
    }
});
fd.append("prop_id",input);
fd.append("file", filetype);

$.ajax({
    type: "POST",
    url: base_url + "applicant_w/upload_docu_by_type",
    data: fd,
    dataType: 'json',
    contentType: false,
    processData: false,
    success: function (response) {

    }
})

```

controller

```
public function upload_docu_by_type() {
    $this->load->helper(array('form', 'url'));
    $F = array();
    $prop_id = sanitize($this->input->post('prop_id'));
    $file = sanitize($this->input->post('file'));

```

i want to get it in controller.

Answer: 
You are missing the the position of the `'Value'` within each group. We can create it with `groupby.cumcount`

```
df.set_index(
    ['group_id', df.groupby('group_id').cumcount() + 1]
).Value.unstack().add_prefix('Value_').reset_index()

   group_id  Value_1  Value_2  Value_3
0         1       23       28       32
1        12       35       23       42

```
Use `groupby` with `cumcount` to fill in your `'value_'` records, and then use `.pivot_table` on the result:

```
df['val_grp'] = 'value_' + (df.groupby('group_id').cumcount() + 1).astype(str)

pvt = df.pivot_table(index='group_id', columns='val_grp', values='Value')

print(pvt)

```

Prints:

```
val_grp   value_1  value_2  value_3
group_id                           
1              23       28       32
12             35       23       42

```

---

As mentioned in the comments by andrew\_reece, this can be done in a single line by doing:

```
pvt = df.assign(idx=(df.groupby("group_id").cumcount()+1).astype(str).str.replace("^(.)", "value_\\1", regex=True)).pivot(index="group_id", columns="idx", values="Value")

```

However, it should be noted that this requires Pandas 23.0 or higher, as this is when the `regex` parameter for `str.replace` was introduced.