从csv文件中提取数据,并使用python制作字典
我有一个如下的csv文件:从csv文件中提取数据,并使用python制作字典,python,csv,dictionary,Python,Csv,Dictionary,我有一个如下的csv文件: 001,citycode,countrycode,usacode,usacountrycode 00457,citycode,countrycode,ugandacode,kampalacode 00976,countrycode,dubaicode,uaecode,dubaiareacode data_dict = {'001' : ['citycode', 'countrycode', 'usacode', 'usacountrycode'],
001,citycode,countrycode,usacode,usacountrycode
00457,citycode,countrycode,ugandacode,kampalacode
00976,countrycode,dubaicode,uaecode,dubaiareacode
data_dict = {'001' : ['citycode', 'countrycode', 'usacode', 'usacountrycode'],
'00457' : ['citycode', 'countrycode', 'ugandacode', 'kampalacode'],
'00976' : ['countrycode', 'dubaicode', 'uaecode', 'dubaiareacode']}
我如何制作这样的数据字典:
001,citycode,countrycode,usacode,usacountrycode
00457,citycode,countrycode,ugandacode,kampalacode
00976,countrycode,dubaicode,uaecode,dubaiareacode
data_dict = {'001' : ['citycode', 'countrycode', 'usacode', 'usacountrycode'],
'00457' : ['citycode', 'countrycode', 'ugandacode', 'kampalacode'],
'00976' : ['countrycode', 'dubaicode', 'uaecode', 'dubaiareacode']}
Python有一个
csv
模块,文档如下所示