Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/285.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

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/blackberry/2.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 如何将unix日期列表转换为可读格式_Python - Fatal编程技术网

Python 如何将unix日期列表转换为可读格式

Python 如何将unix日期列表转换为可读格式,python,Python,我知道如何将unix日期转换为可读日期,但我很难转换整个unix日期列表 以下是我当前的代码: time = df['Time'] list(np.float_(time)) print(datetime.datetime.utcfromtimestamp(time/1000).strftime('%Y-%m-%d %H:%M:%S')) 以及输出: TypeError Traceback (most recent call la

我知道如何将unix日期转换为可读日期,但我很难转换整个unix日期列表

以下是我当前的代码:

time = df['Time']
list(np.float_(time))
print(datetime.datetime.utcfromtimestamp(time/1000).strftime('%Y-%m-%d %H:%M:%S'))
以及输出:

TypeError                                 Traceback (most recent call last)
<ipython-input-52-6532ae588a4d> in <module>()
     45 time = df['Time']
     46 list(np.float_(time))
---> 47 print(datetime.datetime.utcfromtimestamp(time/1000).strftime('%Y-%m-%d %H:%M:%S'))
     48 
     49 

/usr/local/lib/python3.5/dist-packages/pandas/core/series.py in wrapper(self)
    110             return converter(self.iloc[0])
    111         raise TypeError("cannot convert the series to "
--> 112                         "{0}".format(str(converter)))
    113 
    114     return wrapper

TypeError: cannot convert the series to <class 'float'>
TypeError回溯(最近一次调用)
在()
45时间=df[“时间”]
46列表(np.浮动(时间))
--->47打印(datetime.datetime.utcfromtimestamp(time/1000).strftime(“%Y-%m-%d%H:%m:%S”))
48
49
/包装器中的usr/local/lib/python3.5/dist-packages/pandas/core/series.py(self)
110返回转换器(self.iloc[0])
111 raise TypeError(“无法将序列转换为”
-->112“{0}”。格式(str(转换器)))
113
114返回包装器
TypeError:无法将序列转换为

熊猫对这类东西有内置的支持:

time = pandas.to_datetime(df['Time'])
根据
Time
列的格式,您需要指定
to\u datetime
format
参数。看


然后,使用
time.dt.strftime(“%Y-%m-%d%H:%m:%S”)
time
系列(包含
Datetime
对象)转换为一系列字符串是很容易的。如果您的pandas数据帧已经有一列UNIX时间戳浮动,请使用直接将其转换为时间戳字符串

试试这个

time = df['Time'].astype(float).tolist()

列表(np.float_u2;(time))的目的是什么
?您正在创建一个新列表,但没有将其保存到任何地方。我想它会转换原始列表。我想问题是“np.float_uu2;(time)”为什么要将其转换为float?我这样做是因为如果我只删除该行,它只有time=df['time']print(datetime.datetime.utcfromtimestamp(time/1000).strftime(“%Y-%m-%d%H:%m:%S”)会弹出相同的错误up@MikeKassel:您不能分割
数据帧=>
(时间/1000)
        unix_ts
0  140000000000
1   15000000000
0   1970-01-01 00:02:20
1   1970-01-01 00:00:15
Name: unix_ts, dtype: datetime64[ns]
time = df['Time'].astype(float).tolist()