DOWNLOAD: Nen 1010 5e Druk PDF Download .
ARISNEN DISCLAIMER:All contents of this web site are provided on an "as is" and
"as available" basis without warranty of any kind. We try our best to keep it updated, but, we cannot guarantee it.
This is not an official website. You must be 18 or older to access this website. All models are 18 years of age or older.Q:
How to group multiple rows of data using Pandas
I have a dataframe with multiple columns, and multiple rows. Each row corresponds to a subject, and each column represents a different time series.
import pandas as pd
import numpy as np
data = [['subject1','1','1'],['subject2','1','1'],['subject3','1','1']]
data = pd.DataFrame(data, columns = ['subject','period1','period2'])
data = data.T.copy()
I am interested in the first column (subjects). I am also interested in the mean of the first column for each subject. I am trying to do this with pandas. I have tried the following:
data.groupby(['subject'], as_index=False).mean()
The problem is that this seems to return only the mean for all subjects. However, the data looks like this:
subject period1 period2
subject1 1.0 1.0
subject2 1.0 1.0
subject3 1.0 1.0
What I want is something like this:
subject period1 period2
subject1 2.5 1.5
subject2 2.5 1.5
subject3 2.5 1.5
Any help would be greatly appreciated.
A:
Use groupby and aggregate mean:
In [23]: df.groupby(level='subject', axis=1).mean()
Out[23]:
period1 period2
subject be359ba680
Related links:
Comments