Python .pkl文件

时间:2018-10-22 09:03:35

标签: python pickle

我有一个pickle文件,这是我第一次使用这种文件,并且我正尝试使用其中包含的数据来绘制某些内容。

这是我的脚本:

import sys
import os
import pandas as pd
import argparse
import glob
import numpy as np

BASEDIR = '/home/paola/Scrivania/Prova/Python/BSRT/'

def ReadProfilesDF(fin):
    profdf = pd.read_pickle(fin)
    # print profdf.keys()

    print 'Beam : {}. - Plane = {} '.format(np.unique(profdf['beam']), np.unique(profdf['plane']))
    print 'Bunches : {} '.format(np.unique(profdf['bid'].values))
    print 'Timestamps : {}'.format(np.unique(profdf['tsutc'].values))
    return profdf

fname = 'BSRTS.pkl'

fin = '{}{}'.format(BASEDIR, fname)
print 'Input filename {}'.format(fin)
profdf = ReadProfilesDF(fin)

profdf.shape

profdf.head()

selrows = profdf[(profdf['plane'] == 'atH') & (profdf['beam'] == 'atB1') & (profdf['bid'] == 0 )]
selrows.shape
np.unique(selrows['rec'])
selrows.set_index(['tsutc'])
selrows.head()
t1 = pd.Timestamp('2018-07-30 21:14', tz='UTC')
t2 = pd.Timestamp('2018-07-30 21:20', tz='UTC')
selrows2 = selrows[(selrows['tsutc'] > t1) & (selrows['tsutc'] < t2)]
selrows2.head()
selrows2.shape
np.unique(selrows2['rec'])
selrows2[selrows2['rec'] == 0].plot(x='x',y='y')
selrows3 = selrows2[selrows2['tsutc'] == pd.Timestamp('2018-07-30 21:14:00.079976475', tz='UTC')]
np.unique(selrows3['rec'])
selrows3.head()
selrows3.plot(y='x')

运行脚本时,它会向我返回此错误

Traceback (most recent call last):
  File "ReadBSRTProfRecords_toPaola.py", line 109, in <module>
    selrows2[selrows2['rec'] == 0].plot(x='x',y='y')
  File "/home/paola/.local/lib/python2.7/site-packages/pandas/plotting/_core.py", line 2941, in __call__
    sort_columns=sort_columns, **kwds)
  File "/home/paola/.local/lib/python2.7/site-packages/pandas/plotting/_core.py", line 1977, in plot_frame
    **kwds)
  File "/home/paola/.local/lib/python2.7/site-packages/pandas/plotting/_core.py", line 1804, in _plot
    plot_obj.generate()
  File "/home/paola/.local/lib/python2.7/site-packages/pandas/plotting/_core.py", line 258, in generate
    self._compute_plot_data()
  File "/home/paola/.local/lib/python2.7/site-packages/pandas/plotting/_core.py", line 373, in _compute_plot_data
    'plot'.format(numeric_data.__class__.__name__))
TypeError: Empty 'DataFrame': no numeric data to plot

请问有人可以帮助我了解什么问题吗?

0 个答案:

没有答案