0

How can we parse the output from DataFrame.describe()? When we print the result of DataFrame.describe() as shown in examples, it is in string format, which is why it is difficult to parse it.

I understand that the print function might be converting the output into a displayable and readable form. However, it is not easily parseable. How can we achieve this?

galfisher
  • 1,122
  • 1
  • 13
  • 24
Temp O'rary
  • 5,366
  • 13
  • 49
  • 109
  • Do you want to parse output as a string? – hellpanderr Sep 27 '18 at 20:03
  • 1
    Could you put an example of what you mean? I work with it quite often and use the result from df.describe() as a normal dataframe. – Mabel Villalba Sep 27 '18 at 20:04
  • Possible duplicate of [Select rows from a DataFrame based on values in a column in pandas](https://stackoverflow.com/questions/17071871/select-rows-from-a-dataframe-based-on-values-in-a-column-in-pandas) – DJK Sep 27 '18 at 20:21
  • @DJK My question is not about how to parse a DataFrame. My question was how to parse output of describe() of a DataFrame. Hence, both are different. – Temp O'rary Sep 28 '18 at 05:54
  • @TempO'rary, not really, if the output is a dataframe, then the crux of the question is how do I parse a dataframe. It would be like saying a question phrased as "how do I create a dataframe and parse" it is not a duplicate of the link I posted. – DJK Sep 28 '18 at 11:54

2 Answers2

1

print always prints in string format.

But if you check type(df.describe()) then you'll see that it is a dataframe. So you can treat it like one. :)

panktijk
  • 1,574
  • 8
  • 10
0

the output of describe() is a dataframe so you can do:

df = x.describe()

df is a standard DataFrame

DJK
  • 8,924
  • 4
  • 24
  • 40
kevh
  • 323
  • 2
  • 6
  • 1
    So now when I did `df1["numeric"]["mean"]` I get the values. Thanks – Temp O'rary Sep 27 '18 at 20:33
  • I've suggested an edit for more clarification for someone like a beginner – Temp O'rary Sep 28 '18 at 05:59
  • exactly. I'd like to add also that it's tempting to do df1["numeric"].mean to access the serie... but mean is a pre-defined function so it doesn't work. df1["numeric"]["mean"] like you did is the way to go! – kevh Sep 28 '18 at 14:29