您现在的位置是:网站首页> 编程资料编程资料
Python中Timedelta转换为Int或Float方式_python_
2023-05-26
248人已围观
简介 Python中Timedelta转换为Int或Float方式_python_
Timedelta转换为Int或Float方式
Pandas处理
import pandas as pd dataSet['t'] =dataSet['time'].astype('timedelta64[D]').astype(float) dataSet['t'] .head()Numpy处理
import numpy as np dataSet['t']=(dataSet['time']/np.timedelta64(1, 'D')).astype(float) dataSet['t'] .head()
区别
方法(一)pandas是直接提取days数值,如90 days 04:48:00提取数值90;
方法(二)numpy是把整个时间进行换算,如90 days 04:48:00转化为90.200000。
可以根据实际需求,选择不同的方法进行时间转换。
timedelta、float 互转

以上为个人经验,希望能给大家一个参考,也希望大家多多支持。
相关内容
- python的endswith()的使用方法及实例_python_
- python 对excel交互工具的使用详情_python_
- Python读取hdf文件并转化为tiff格式输出_python_
- Python利用Turtle绘画简单图形_python_
- Python OpenCV中的drawMatches()关键匹配绘制方法_python_
- Python cv.Canny()方法参数与使用方法_python_
- Python OpenCV 图像矫正的原理实现_python_
- Python OpenCV Canny边缘检测算法的原理实现详解_python_
- Python OpenCV Hough直线检测算法的原理实现_python_
- python中字典的常见操作总结2_python_
