Skip to content

Instantly share code, notes, and snippets.

@gerigk
Created March 21, 2012 16:30
Show Gist options
  • Save gerigk/2149322 to your computer and use it in GitHub Desktop.
Save gerigk/2149322 to your computer and use it in GitHub Desktop.
@classmethod question
@classmethod
def from_dict(cls, data, orient='columns', dtype=None):
from collections import defaultdict
orient = orient.lower()
if orient == 'index':
# TODO: this should be seriously cythonized
new_data = defaultdict(dict)
for index, s in data.iteritems():
for col, v in s.iteritems():
new_data[col][index] = v
data = new_data
elif orient != 'columns': # pragma: no cover
raise ValueError('only recognize index or columns for orient')
return DataFrame(data, dtype=dtype)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment