我想将时间转换为数字,例如(16:40到16.4)
15:40到15,4使用python
query = "SELECT date,time,windspeed,rainfall,winddirrection,temperature FROM *****"
cur.execute(query)
data_kampi = cur.fetchall()
data1=np.array([data_kampi], dtype='object')
N1=data1.shape
x=np.squeeze(data1)
#convert numpy to pandas
xpandas=pd.DataFrame(x, columns=["Date", "Time", "Windspeed", "Rainfall", "Winddirection", "Temperature"])
#print(xpandas.head())
xpandas.to_csv("test.csv", header=True, index=False)
xnumpy=np.array(xpandas)
答案 0 :(得分:0)
如果我对您的理解正确,则可以使用以下方法:
xpandas['Time'] = xpandas['Time'].apply(lambda x: float(str(x).replace(':', '.')))
您可能需要先更改格式:
xpandas['Time'] = pd.to_datetime(xpandas['Time'], format='%H:%M').dt.strftime('%H:%M')