this question has answer here:
- creating dictionary csv file? 8 answers
if have csv file looks this:
name | value 1 | value 2
foobar | 22558841 | 96655
barfool | 02233144 | 3301144
how can make dictionary looks this:
dict = { 'foobar': { 'value 1': 2255841, 'value 2': 9665 }, 'barfool': { 'value 1': 02233144, 'value 2': 3301144 } }
if use pandas
:
import pandas pd pd.read_csv('test.csv', delimiter='|', index_col='name').t.to_dict() # {'barfool': {'value 1': 2233144, 'value 2': 3301144}, # 'foobar': {'value 1': 22558841, 'value 2': 96655}}
Comments
Post a Comment