Change Python Pandas exit describe

Is it possible to omit any conclusion from the description of pandas? This command gives me exactly what I want with the output of the table (count and mean oftimeTime by simpleDate)

df.groupby('simpleDate').executeTime.describe().unstack(1) 

Nevertheless, all that I want, I consider and mean. I want to remove std, min, max, etc. So far, I have only read how to resize a column.

I assume that the answer will be to rewrite the string, rather than use the describe, but I did not have a successful simpleDate grouping and to get the score with an average executeTime.

I can do the count by date:

 df.groupby(['simpleDate']).size() 

or executeTime by date:

 df.groupby(['simpleDate']).mean()['executeTime'].reset_index() 

But I can not understand the syntax for combining them.

My desired result:

  count mean 09-10-2013 8 20.523 09-11-2013 4 21.112 09-12-2013 3 18.531 ... .. ... 
+6
source share
4 answers

Describe how the series returns, so you can just choose what you want

 In [6]: s = Series(np.random.rand(10)) In [7]: s Out[7]: 0 0.302041 1 0.353838 2 0.421416 3 0.174497 4 0.600932 5 0.871461 6 0.116874 7 0.233738 8 0.859147 9 0.145515 dtype: float64 In [8]: s.describe() Out[8]: count 10.000000 mean 0.407946 std 0.280562 min 0.116874 25% 0.189307 50% 0.327940 75% 0.556053 max 0.871461 dtype: float64 In [9]: s.describe()[['count','mean']] Out[9]: count 10.000000 mean 0.407946 dtype: float64 
+16
source
Attribute

.describe() generates a dataframe, where count, std, max ... are the index values, so according to the documentation you should use, for example:

 df.describe().loc[['count','max']] 
+9
source

The @Jeff solution provides simple work for series.

@Rafa is located at: df.describe().info() shows that the resulting framework has Index: 8 entries, count to max

df.describe().loc[['count','max']] works, but df.groupby('simpleDate').describe().loc[['count','max']] , which sets OP , does not work.

I think the solution could be as follows:

 df = pd.DataFrame({'Y': ['A', 'B', 'B', 'A', 'B'], 'Z': [10, 5, 6, 11, 12], }) 

grouping df on Y :

 df_grouped=df.groupby(by='Y') In [207]df_grouped.agg([np.mean, len]) Out[207]: Z mean len YA 10.500 2 B 7.667 3 
+1
source

By following the description, you can expand the indexes and then truncate normally.

df.describe().unstack()[['count','max']]

0
source

Source: https://habr.com/ru/post/955054/


All Articles