Created
March 21, 2012 16:30
-
-
Save gerigk/2149322 to your computer and use it in GitHub Desktop.
@classmethod question
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@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