2021年4月2日星期五

Pandas: Extracting data from sorted dataframe

Consider I have a dataframe with 2 columns: the first column is 'Name' in the form of a string and the second is 'score' in type int. There are many duplicate Names and they are sorted such that the all 'Name1's will be in consecutive rows, followed by 'Name2', and so on. Each row may contain a different score.The number of duplicate names may also be different for each unique string.'

I wish to extract data afrom this dataframe and put it in a new dataframe such that There are no duplicate names in the name column, and each name's corresponding score is the average of his scores in the original dataframe.

I've provided a picture for a better visualization: x need not necessarily be equal to y.

https://stackoverflow.com/questions/66927880/pandas-extracting-data-from-sorted-dataframe April 03, 2021 at 01:02PM

没有评论:

发表评论