Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the format of the 'orient' agument to pandas.DataFrame.to_json()?

Tags:

python

pandas

Looking at the pandas Documentation on DataFrame's to_json method, the orient argument is ambiguously explained. The type of the argument it accepts is a string, not a dict. However it seems like there are actually three things it can accept and each has their own default: Series (default 'index'), DataFrame (default 'columns'), and "The format of the JSON string" (no default).

I'd like to know what the acceptable values for the orient argument are and what each of them do to the output json.

like image 516
Andrew Farrell Avatar asked Mar 09 '15 22:03

Andrew Farrell


1 Answers

The format of the JSON string is just how the output will look like for every parameter as following

  • split : dict like {index -> [index], columns -> [columns], data -> [values]}
  • records : list like [{column -> value}, ... , {column -> value}]
  • index : dict like {index -> {column -> value}}
  • columns : dict like {column -> {index -> value}}
  • values : just the values array
like image 70
Mostafa Mahmoud Avatar answered Oct 02 '22 12:10

Mostafa Mahmoud