擅长:python、mysql、java
<p>您可以使用<code>pd.read_csv</code>函数读取<code>csv</code>文件。然后,您可以使用<code>iterrows()</code>方法迭代<code>DataFrame</code>的行,在每次迭代中创建{<cd5>}并将其追加到列表中。在</p>
<pre><code>import pandas as pd
from collections import OrderedDict
df = pd.read_csv("data.csv", sep="\t", index_col=0)
dicts = list()
for i, row in df.iterrows():
d = OrderedDict(zip(row.index.tolist(),
row.tolist()))
dicts.append(d)
</code></pre>
<p>输出将是:</p>
^{pr2}$
<p>编辑:<code>tags</code>将是字符串,而不是列表。如果要将其转换为列表使用</p>
<pre><code>import ast
df['tags'] = df['tags'].apply(lambda x: ast.literal_eval(x))
</code></pre>