大熊猫每行的情节

时间:2017-03-14 21:06:24

标签: python pandas matplotlib seaborn

我正在尝试为每个“Klas”创建一个折线图。但我只能按每列绘图。是否可以每行绘制一条线?

    Score   Score.1     Score.2     Score.3     Score.4     Score.5     Score.6     Score.7     Score.8     Score.9     ...     Score.31    Score.32    Score.33    Score.34    Score.35    Score.36    Score.37    Score.38    Score.39    e
Klas                                                                                    
A   0.826087    0.521739    0.565217    0.478261    0.652174    0.913043    0.347826    0.869565    0.478261    0.260870    ...     0.869565    0.434783    0.652174    0.739130    0.956522    0.652174    0.521739    0.739130    0.869565    0.616304
B   0.814815    0.592593    0.740741    0.592593    0.777778    0.962963    0.259259    0.851852    0.555556    0.518519    ...     0.777778    0.444444    0.666667    0.925926    0.962963    0.444444    0.703704    0.703704    0.888889    0.654630
C   0.846154    0.653846    0.653846    0.653846    0.538462    1.000000    0.461538    0.884615    0.538462    0.538462    ...     0.769231    0.230769    0.807692    0.769231    0.961538    0.730769    0.615385    0.730769    0.884615    0.671154
D   0.863636    0.636364    0.727273    0.772727    0.636364    0.909091    0.363636    0.863636    0.545455    0.681818    ...     0.818182    0.318182    0.863636    0.909091    0.954545    0.818182    0.636364    0.954545    0.863636    0.705682
E   0.966667    0.566667    0.666667    0.500000    0.733333    0.900000    0.300000    0.933333    0.200000    0.366667    ...     0.766667    0.533333    0.666667    0.700000    0.933333    0.566667    0.500000    0.800000    0.866667    0.635000
F   0.962963    0.481481    0.518519    0.444444    0.518519    0.814815    0.259259    0.814815    0.518519    0.481481    ...     0.740741    0.259259    0.703704    0.703704    0.962963    0.666667    0.407407    0.777778    0.814815    0.595370
G   0.827586    0.448276    0.586207    0.689655    0.689655    0.862069    0.448276    0.827586    0.517241    0.448276    ...     0.896552    0.241379    0.862069    0.758621    0.965517    0.620690    0.551724    0.965517    0.931034    0.663793
I   0.962963    0.481481    0.814815    0.518519    0.629630    0.962963    0.370370    0.814815    0.407407    0.407407    ...     0.740741    0.259259    0.925926    0.888889    0.962963    0.518519    0.629630    0.888889    0.777778    0.662963
J   0.965517    0.586207    0.689655    0.586207    0.551724    0.758621    0.413793    0.896552    0.517241    0.379310    ...     0.827586    0.206897    0.724138    0.793103    0.965517    0.655172    0.620690    0.758621    0.931034    0.635345
K   0.892857    0.607143    0.714286    0.642857    0.571429    0.892857    0.357143    0.857143    0.392857    0.500000    ...     0.785714    0.285714    0.821429    0.857143    0.892857    0.678571    0.642857    0.928571    0.821429    0.646429
L   0.933333    0.466667    0.666667    0.700000    0.666667    0.800000    0.433333    0.733333    0.433333    0.333333    ...     0.833333    0.300000    0.766667    0.800000    1.000000    0.500000    0.533333    0.833333    0.866667    0.658333
M   1.000000    0.695652    0.652174    0.478261    0.521739    0.826087    0.260870    0.739130    0.304348    0.347826    ...     0.608696    0.347826    0.695652    0.739130    0.956522    0.434783    0.260870    0.652174    0.782609    0.603261
N   0.892857    0.500000    0.714286    0.571429    0.642857    0.928571    0.500000    0.892857    0.357143    0.464286    ...     0.928571    0.178571    0.785714    0.785714    1.000000    0.571429    0.500000    0.857143    0.892857    0.656250
O   0.913043    0.521739    0.695652    0.478261    0.652174    0.913043    0.391304    0.826087    0.478261    0.521739    ...     0.826087    0.260870    0.913043    0.739130    0.956522    0.565217    0.695652    0.782609    0.652174    0.661957
P   0.962963    0.592593    0.629630    0.555556    0.666667    0.888889    0.518519    0.925926    0.370370    0.592593    ...     0.814815    0.296296    0.814815    0.925926    0.962963    0.666667    0.592593    0.814815    0.888889    0.684259
Q   0.833333    0.433333    0.633333    0.600000    0.600000    0.866667    0.400000    0.800000    0.566667    0.500000    ...     0.866667    0.333333    0.733333    0.733333    0.966667    0.566667    0.600000    0.866667    0.833333    0.648333
R   0.956522    0.826087    0.695652    0.565217    0.608696    0.913043    0.608696    0.913043    0.782609    0.608696    ...     0.869565    0.347826    0.869565    0.913043    0.956522    0.434783    0.695652    0.913043    0.956522    0.721739
S   0.925926    0.666667    0.629630    0.518519    0.814815    0.925926    0.629630    0.851852    0.629630    0.518519    ...     0.851852    0.259259    0.851852    0.740741    1.000000    0.592593    0.666667    0.777778    0.925926    0.681481

1 个答案:

答案 0 :(得分:0)

这是一个带有随机块的简短示例,以帮助说明问题。这将适用于您的数据。

a.select(lambda row: (row[0] == 'a' and row[1] == 'x0') or (row[0] == 'b' and row[1] == 'x1'))

plot 1

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

%matplotlib inline

#creating random block
data = {'a' : np.random.randint(0, 10, size = 10),
        'b' : np.random.randint(0, 10, size = 10),
        'c' : np.random.randint(0, 10, size = 10),
        'd' : np.random.randint(0, 10, size = 10),
        'e' : np.random.randint(0, 10, size = 10)}

df = pd.DataFrame(data) 

#what is happening
df.plot()

plot 2