擅长:python、mysql、java
<p>也许和熊猫在一起?你知道吗</p>
<pre><code>import pandas as pd
# Load the data
data = pd.read_csv(filename)
# Reshaping
data_reshaped = pd.melt(df).groupby('variable').agg(list).reset_index().T
data_reshaped.index = ['category','list']
# Convert to json
data_reshaped.to_json()
</code></pre>
<p>你会得到:</p>
<pre><code>'{"0":{"category":"Egypt","list":["Cairo","Alexandria "]},
"1":{"category":"USA","list":["California","Texas"]}}'
</code></pre>
<p>这不是你想要的,但这是个开始。你知道吗</p>