Matplotlib 打印数据框,但大多数列都有零

Matplotlib 打印数据框,但大多数列都有零,matplotlib,pandas,ipython,Matplotlib,Pandas,Ipython,我对熊猫和ipython是新手,我只是设置了一切,目前正在四处玩耍。我有以下数据框: Field 10 20 30 40 50 60 70 80 90 95 0 A 0 0 0 0 0 0 0 0 1 3 1 B 0 0 0 0 0 0 0 1 4 14 2 C 0 0 0 0 0 0 0

我对熊猫和ipython是新手,我只是设置了一切,目前正在四处玩耍。我有以下数据框:

  Field  10   20   30   40   50   60   70   80   90   95
0   A   0    0    0    0    0    0    0    0    1    3
1   B   0    0    0    0    0    0    0    1    4   14
2   C   0    0    0    0    0    0    0    1    2    7
3   D   0    0    0    0    0    0    0    1    5   15
4   u   0    0    0    0    0    0    0    1    5   14
5   K   0    0    0    0    0    0    1    2    7   21
6   S   0    0    0    0    0    0    0    1    3    8
7   E   0    0    0    0    0    0    0    1    3    8
8   F   0    0    0    0    0    0    0    1    6   16
我使用csv文件导入此数据:

df = pd.read_csv('/mycsvfile.csv', 
                         index_col=False, header=0)
正如您可以看到的,列的post为零,此数据帧具有大量行,但在列中,大多数行可能为零,而剩下的一行或两行的值类似于“70”

我想知道我怎样才能把它转换成一个漂亮的图表,在那个里我可以用重点显示70,80,95列


我找到了以下教程:
[
][1]
但我仍然无法得到一个好的数字。

这取决于您希望如何处理零值,但这里有一种方法:

df = pd.DataFrame({'a': [0,0,0,0,70,0,0,90,0,0,80,0,0],
                       'b': [0,0,0,50,0,60,0,90,0,80,0,0,0]})

fig, axs = plt.subplots(1,2,figsize=(10,4))

# plot the original, for comparison
df.plot(ax=axs[0])

for name, col in df.iteritems():
    col[col != 0].plot(ax=axs[1], label=name)

axs[1].set_xlim(df.index[0],df.index[-1])
axs[1].set_ylim(bottom=0)
axs[1].legend(loc=0)


您也可以使用
.replace(0,np.nan)
,但matplotlib不会在两者之间画线。因此,您可能最终会在列上循环(然后使用
dropna().plot()

这取决于您希望如何处理零值,但这里有一种方法:

df = pd.DataFrame({'a': [0,0,0,0,70,0,0,90,0,0,80,0,0],
                       'b': [0,0,0,50,0,60,0,90,0,80,0,0,0]})

fig, axs = plt.subplots(1,2,figsize=(10,4))

# plot the original, for comparison
df.plot(ax=axs[0])

for name, col in df.iteritems():
    col[col != 0].plot(ax=axs[1], label=name)

axs[1].set_xlim(df.index[0],df.index[-1])
axs[1].set_ylim(bottom=0)
axs[1].legend(loc=0)


您也可以使用
.replace(0,np.nan)
,但matplotlib不会在两者之间画线。因此,您最终可能会在列上循环(然后使用
dropna().plot()
例如)。

谢谢,您认为直方图是可能的吗?X轴为场,y轴为10,20。。。。?我怎么做历史记录?谢谢,你认为直方图可能吗?X轴为场,y轴为10,20。。。。?我怎么能做历史记录?