我有一个很大的 CSV 文件,其中有一列名为 TIME。它写为 1318,我想使用 Python/Pandas 将数据转换为 13:18 并将其视为时间而不是 int64。
我试过这样的事情,但这不是我想要的:
df['TIME'] = pd.to_datetime(df['TIME'])
Run Code Online (Sandbox Code Playgroud)
因为我得到了这个:
1970-01-01 00:00:00.000001318
1970-01-01 00:00:00.000001041
1970-01-01 00:00:00.000000853
Run Code Online (Sandbox Code Playgroud)
有任何想法吗?
这是来自谷歌距离矩阵的回复。我只想将这两个值作为输出,我正在尝试用 Python 提取它。
{
"destination_addresses" : [ "Hoorn, Nederland" ],
"origin_addresses" : [ "Amsterdam, Nederland" ],
"rows" : [
{
"elements" : [
{
"distance" : {
"text" : "45,0 km",
"value" : 44952
},
"duration" : {
"text" : "40 min.",
"value" : 2423
},
"status" : "OK"
}
]
}
],
"status" : "OK"
}
Run Code Online (Sandbox Code Playgroud)
这是我迄今为止尝试过的。我想每 15 分钟收到一次来自 Google 的回复并将其写入文件。但是在文件中,我只想要距离和持续时间的值,而我没有运气实现这一点。我不确定来自 Google 的回复是否是正确的 JSON,所以我尝试了 json.loads 但它不允许我从回复中提取某些部分。有任何想法吗?
import requests
import json
import datetime
from apscheduler.schedulers.blocking import BlockingScheduler
uri = "https://maps.googleapis.com/maps/api/distancematrix/json?origins=Amsterdam&destinations=Hoorn&mode=driving&key=" …Run Code Online (Sandbox Code Playgroud)