Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/356.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_Pandas - Fatal编程技术网

Python 熊猫选择一个嵌套列并打印它

Python 熊猫选择一个嵌套列并打印它,python,pandas,Python,Pandas,我有一个像这样的数据框 Category A CategoryB Thing1 Thing2 Thing3 Thing1 Thing2 Thing3 0 x x x x x x 1 x x x x x x 2 x x x x x x 我正在尝试类似于df.plot(x='A.Thing1',y='A.Thing2')的

我有一个像这样的数据框

 Category A            CategoryB
 Thing1 Thing2 Thing3  Thing1 Thing2 Thing3
0  x      x      x     x      x      x
1  x      x      x     x      x      x
2  x      x      x     x      x      x

我正在尝试类似于
df.plot(x='A.Thing1',y='A.Thing2')
的方法,但这当然不起作用。

您可以将多索引列作为元组传递给
数据帧。plot

示例

import pandas as pd
import numpy as np
import matplotlib.pyplot as plt    

# Setup
midx = pd.MultiIndex.from_product([['Category A', 'Category B'],
                                   ['Thing 1', 'Thing 2']])

np.random.seed(0)
df = pd.DataFrame(np.random.randn(10, 4), columns=midx)
print(df)

  Category A           Category B          
     Thing 1   Thing 2    Thing 1   Thing 2
0   1.764052  0.400157   0.978738  2.240893
1   1.867558 -0.977278   0.950088 -0.151357
2  -0.103219  0.410599   0.144044  1.454274
3   0.761038  0.121675   0.443863  0.333674
4   1.494079 -0.205158   0.313068 -0.854096
5  -2.552990  0.653619   0.864436 -0.742165
6   2.269755 -1.454366   0.045759 -0.187184
7   1.532779  1.469359   0.154947  0.378163
8  -0.887786 -1.980796  -0.347912  0.156349
9   1.230291  1.202380  -0.387327 -0.302303

[外]


曾经面对过同样的问题。试试这个:
df.plot(x=('Category A', 'Thing 1'),
        y=('Category B', 'Thing 2'),
        kind='scatter')