Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/python-3.x/17.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 我能在熊猫中得到一个额外的标题作为所有列顶部的名称吗_Python_Python 3.x_Pandas - Fatal编程技术网

Python 我能在熊猫中得到一个额外的标题作为所有列顶部的名称吗

Python 我能在熊猫中得到一个额外的标题作为所有列顶部的名称吗,python,python-3.x,pandas,Python,Python 3.x,Pandas,我想为数据帧添加标题作为标题。 例如,假设这是数据帧 count mean std min 25% 50% 75% max Gender F 4.0 86.250 3.862 82.0 83.5 86.5 89.25 90.0 M 6.0 85.833 5.565 78.0 82.

我想为数据帧添加标题作为标题。 例如,假设这是数据帧

         count    mean    std   min   25%   50%    75%   max
 Gender                                                     
 F         4.0  86.250  3.862  82.0  83.5  86.5  89.25  90.0
 M         6.0  85.833  5.565  78.0  82.0  86.5  90.25  92.0
我想在顶部标题或行中添加一些标题,如下所示

                                Analysis
         count    mean    std   min   25%   50%    75%   max
 Gender                                                     
 F         4.0  86.250  3.862  82.0  83.5  86.5  89.25  90.0
 M         6.0  85.833  5.565  78.0  82.0  86.5  90.25  92.0

关闭,您需要的是<代码>多索引,但它不是在中间,而是在左边:

df.columns = pd.MultiIndex.from_product([['Analysis'], df.columns])
print (df)
       Analysis                                              
          count    mean    std   min   25%   50%    75%   max
Gender                                                       
F           4.0  86.250  3.862  82.0  83.5  86.5  89.25  90.0
M           6.0  85.833  5.565  78.0  82.0  86.5  90.25  92.0