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

Python 如何搜索我的时间数据列表

Python 如何搜索我的时间数据列表,python,pandas,matplotlib,Python,Pandas,Matplotlib,我有下面的工作代码。目前,我正在从sav文件中提取数据,将其导出为csv文件,然后绘制这些数据。它看起来不错,但我想放大它,我不完全知道怎么做。这是因为我的时间按以下格式列出: 20141107B205309Y 代码中既有字母也有数字,所以我不知道该怎么办 我想我可以用两种方法来做: 我正在考虑使用python来“修剪”时间数据,使其在csv文件中仅显示“20141107”,这将使浏览变得容易 我不确定这是否可能,但如果有人知道我如何使用“xrange=[]”搜索代码,就像我通常使用数据一样

我有下面的工作代码。目前,我正在从sav文件中提取数据,将其导出为csv文件,然后绘制这些数据。它看起来不错,但我想放大它,我不完全知道怎么做。这是因为我的时间按以下格式列出:

20141107B205309Y
代码中既有字母也有数字,所以我不知道该怎么办

我想我可以用两种方法来做:

  • 我正在考虑使用python来“修剪”时间数据,使其在csv文件中仅显示“20141107”,这将使浏览变得容易

  • 我不确定这是否可能,但如果有人知道我如何使用“xrange=[]”搜索代码,就像我通常使用数据一样

  • 我的代码:

    import scipy.io as spio
    import numpy as np
    import csv
    import pandas as pd
    import matplotlib as plt
    
    np.set_printoptions(threshold=np.nan)
    onfile='/file'
    finalfile='/fileout'
    
    s=spio.readsav(onfile,python_dict=true,verbose=true)
    
    time=np.asarray(s["time"])
    data=np.asarray(s["data"])
    
    d=pd.DataFrame({'time':time,'data':data})
    d.to_csv(finalfile,sep=' ', encoding='utf-u',header=True)
    d.plot(x='time',y='data',kind='line')
    

    也许可以尝试将s[“time”]转换为日期时间对象列表,而不是字符串

        from datetime import datetime
        date_list = [datetime.strptime(d, '%Y%m%dB%H%M%SY') for d in s["time"]]
        time=np.asarray(date_list)
    
    此处,str对象使用以下格式转换为datetime对象“%Y%m%dB%H%m%SY”

    这里


    如果您的数据集是一致的,那么熊猫可以为您修剪列。结账可以使用“B”字符进行拆分。之后,将列转换为日期。 可以使用将序列转换为日期

    %d is the day number
    %m is the month number
    %b is the month abbreviation
    %y is the year last two digits
    %Y is the all year