0

我正在尝试使用新的 Morningstar Jupyter Notebook 进行一些科学分析。我的目标是建立一个包含 17 个不同基准的协方差表。我遇到的问题是数据是交叉制表的。日期作为标题输入,返回索引到第一行。我试图弄清楚如何在左侧有一个日期索引,而我的所有 17 个索引都在顶部。我尝试过转置和删除列。我试过提取行。我只是在学习 Python

问题:

在此处输入图像描述

4

1 回答 1

0

It looks like you want to transpose your data. You can try something like

df_transposed = df.transpose()
df_transposed

This should set the columns of your first df to be the index of the new one. (Name will be the first row in the table) You can then set the column names to the first row of names if you want to refer to each column by the value of the Name. Something like this should work.

df_transposed.columns = df_transposed.loc['Name'].tolist()
于 2021-11-17T04:11:50.910 回答