2

I am trying to create the summary statistics for the stock returns of Apple and Alphabet. I already have the excel file with all the information and the (small) code bellow:

import pandas as pd
Data = pd.read_excel('Exercise1_DataPython.xlsx')
example_series = Data.describe()
print (example_series)

However, when I run this it returns "count, unique, top and freq" instead of "mean, min, max, etc". Can someone explain me how to solve this problem? And how can I get the mean, min, max, etc only for one specific column?

Thanks!

akshat
  • 1,219
  • 1
  • 8
  • 24
Ana Sofia
  • 35
  • 1
  • 2
  • 7
    This is because your data is not numeric. [Edit](https://stackoverflow.com/posts/50027737/edit) your question and add the output of `print(Data.dtypes)`. – pault Apr 25 '18 at 17:06
  • Related: [Pandas .describe() only returning 4 statistics on int dataframe (count, unique, top, freq)… no min, max, etc](https://stackoverflow.com/questions/38433672/pandas-describe-only-returning-4-statistics-on-int-dataframe-count-unique) and [Pandas 'describe' is not returning summary of all columns](https://stackoverflow.com/questions/24524104/pandas-describe-is-not-returning-summary-of-all-columns) – pault Apr 25 '18 at 17:13

1 Answers1

2

Use the include parameter:

df = pd.DataFrame({ 'object': ['a', 'b', 'c'],
                     'numeric': [1, 2, 3],
                     'categorical': pd.Categorical(['d','e','f'])
                  })

df.describe(include='all')

Output:

        categorical  numeric object
count            3      3.0      3
unique           3      NaN      3
top              f      NaN      c
freq             1      NaN      1
mean           NaN      2.0    NaN
std            NaN      1.0    NaN
min            NaN      1.0    NaN
25%            NaN      1.5    NaN
50%            NaN      2.0    NaN
75%            NaN      2.5    NaN
max            NaN      3.0    NaN
Scott Boston
  • 147,308
  • 15
  • 139
  • 187
  • 1
    It's hard to tell without a [mcve] but I believe OP's problem is that she has numeric columns being treated as strings. – pault Apr 25 '18 at 17:14
  • @pault You maybe right on this. This an attempt to get describe to show 'string' and 'categorical' results also. – Scott Boston Apr 25 '18 at 17:16