擅长:python、mysql、java
<p>@giser\u yugang找到了理想的解决方案。<strong>Pandas</strong>具有内置方法<code>DataFrame.to_dict(orient='dict')</code>,该方法转换数据帧并返回字典,其中可以使用参数<code>orient</code>自定义键值对。<br/>
“东方”中的“记录”给出了你想要的结果。你知道吗</p>
<p>因此,您的数据帧:</p>
<p><a href="https://i.stack.imgur.com/If1Eb.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/If1Eb.png" alt="dataframe"/></a></p>
<p>使用后:</p>
<pre><code>df.to_dict(orient='records')
</code></pre>
<p>提供:</p>
<pre><code>[{'Example 1': 'Cat',
'Example 2': 'Dog',
'Example 3': 'Mouse',
'Example 4': 'Horse'},
{'Example 1': 'Cow',
'Example 2': 'Ant',
'Example 3': 'Pig',
'Example 4': 'Elephant'}]
</code></pre>