Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/280.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
从csv文件中提取数据,并使用python制作字典_Python_Csv_Dictionary - Fatal编程技术网

从csv文件中提取数据,并使用python制作字典

从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'],

我有一个如下的csv文件:

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
模块,文档如下所示