Python中文
首页
教程
问答
标签
搜索
登录
注册
PandasCSV:CSV to orderedDi
回答此问题可获得
20
贡献值,回答如果被采纳可获得
50
分。
<p>将已排序字典保存为csv的最佳方法是什么,将csv文件加载到相同格式的有序词典中,编辑它们并将它们保存回原样。在</p> <p>我最初保存的数据如下:</p> <pre><code>gifs_info_list=[] gifs_info_list.<a href="https://www.cnpython.com/list/append" class="inner-link">append</a>(OrderedDict([('ID','aswd'),('class','c1'),('mu',gif["parameters"]["mu"]),('sigma','23'), ('tags', [u'movies', u'hitler']),('flag1',False),('flag2',False),('flag3',False)])) </code></pre> <p>下面是我如何处理orderedDict2CSV</p> ^{pr2}$ <p>这会将数据保存到csv,如下所示:</p> <pre><code> ID class mu sigma tags flag1 flag2 flag3 0 fdex c1 39.8348689258 2.49703182691 [u'movies', u'hitler'] False False False 2 11AE c2 38.7252538197 2.23352853216 [u'movie', u'mark millar'] False False False 3 p9ut c1 37.775785901 2.33519338409 [] False False False </code></pre> <p>我需要编写CSV2OrderedDict,将csv中的数据加载到与创建时格式相同的ordereddict列表中。我该怎么做?在</p>
0 条评论
分类:
Python问答
请先
登录
后评论
默认排序
时间排序
1 个回答
匿名
1天前
擅长:python、mysql、java
<pre><code>def csv_to_list(fname): df = pd.from_csv(fname, index_col=0) return [OrderedDict(row[1]) for row in df.iterrows()] </code></pre>
请先
登录
后评论
针对此问题:
更多的回答
关注
89
关注
收藏
1
收藏,
216
浏览
网友 提问于 2天前
相关Python问题
如何将Python中的列表复制到给定的目标中?
6 回答
如何将python中的列表插入SQL表
10 回答
如何将python中的列表转换为numpy数组以放入十位
7 回答
如何将python中的列表输入javascript?
2 回答
如何将python中的列表返回给dag?
2 回答
如何将Python中的列表项重新排列成成对的元组/列表?
7 回答
如何将Python中的初始化对象序列化为XML?
10 回答
如何将python中的十进制字符串转换为数字?
5 回答
如何将Python中的原始输入文本转换为Tkinter中的标签?
1 回答
如何将python中的反斜杠命令转换为在Linux上运行
6 回答
如何将python中的命令行参数转换为字典?
5 回答
如何将python中的图像值传递到kivy中的kv文件?
3 回答
如何将Python中的图像数组(枕头对象)上传到Google云
6 回答
如何将Python中的图像编码为Base64?
2 回答
如何将python中的图像调整为灰度低分辨率,如MNIST时尚数据?
3 回答
如何将python中的多个html输出保存到单个文件(或多个)中?
2 回答
如何将Python中的多个ifelse语句重构为一个函数?
1 回答
如何将Python中的多处理与Django结合使用,从xml文件创建数千个模型实例?
10 回答
如何将python中的多级API响应转换为dataframe
2 回答
如何将python中的多线程编程模型转换为异步/等待模型?
3 回答