I got the following table in pandas:
| x | y |
|---|---|
| 1 | 1 |
| 2 | 3 |
| 2 | 5 |
| 2 | 4 |
| 1 | 4 |
| 1 | 5 |
I would like to see the pattern of variable x, so I would like to see the pattern goes.
In the table you would see x=1 then x=2 for three times and then go back to x=1 twice.
| x | # occurance | first y value | last y value |
|---|---|---|---|
| 1 | 1 | 1 | 1 |
| 2 | 3 | 3 | 4 |
| 1 | 2 | 4 | 5 |
I initially tried groupby but using groupby would group all x together, and that is not the desired way.
For convenience, I should provide the content of the dataframe.
data = {'x': [1, 2, 2, 2, 1, 1],
'y': [1, 3, 5, 4, 4, 5]}
df = pd.DataFrame(data)
Thanks in advance.