0

I have a similar dataframe:

x | y
1 | 1
3 | 1
3 | 1
4 | 1
5 | 2
5 | 2
9 | 2
8 | 2

And I want to resample this dataframe such that x values with the same y value is averaged. In other words:

     x       |    y
(1+3+3+4)/4  |    1
(5+5+9+8)/4  |    2

I've looked into the pandas.DataFrame.resample function, but not sure how to do this without timestamps.

fendrbud
  • 89
  • 1
  • 11
  • looks like a [groupby](https://pandas.pydata.org/pandas-docs/stable/reference/api/pandas.core.groupby.GroupBy.mean.html) operation – sammywemmy Nov 10 '20 at 09:42

1 Answers1

1

The following might return what you're looking for:

import pandas
df = pandas.DataFrame({"x":[1,3,3,4,5,5,9,8],"y":[1,1,1,1,2,2,2,2]})
df.groupby(["y"]).mean().reset_index()
celerygemini
  • 148
  • 1
  • 13