Skip to content

Dmitrii-I/as-dataframe

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

31 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

as-dataframe

https://api.travis-ci.org/Dmitrii-I/as-dataframe.svg?branch=master

Convert dictionaries to dataframes effortlessly with as-dataframe

Installation

pip install as-dataframe

Examples

Convert a plain dictionary into a dataframe:

>>> from as_dataframe import as_dataframe
>>> plain_dict = {'first name': 'John', 'last name': 'Doe'}
>>> print(as_dataframe(plain_dict))
  first name last name
0       John       Doe

Dictionaries with list values are supported too of course:

>>> from as_dataframe import as_dataframe
>>> dict_with_list_values = {'first name': ['John', 'Alice'], 'last name': ['Doe', 'Doe']}
>>> print(as_dataframe(dict_with_list_values))
  first name last name
0       John       Doe
1      Alice       Doe

Convert a nested dictionary into a dataframe:

>>> from as_dataframe import as_dataframe
>>> nested_dict = {'names': {'first': ['John', 'Alice'], 'last': ['Doe', 'Doe']}}
>>> print(as_dataframe(nested_dict))
  names.first names.last
0        John        Doe
1       Alice        Doe

Convert a list of nested dictionaries into a dataframe:

>>> from as_dataframe import as_dataframe
>>> nested_dicts = [{'a': {'b': [1, 2], 'c': [3, 4]}}, {'a': {'b': [5, 6], 'c': [7, 8]}}]
>>> print(as_dataframe(nested_dicts))
   a.b  a.c
0    1    3
1    2    4
2    5    7
3    6    8