[英]How to concatenate multiple Pandas series' of type string into a single Pandas series while inserting hyphens and spaces?
问题:
我有一些原始数据,涉及与日期和时间信息有关的问题-像没有冒号将小时和分钟分开,以及包含2400
。 我正在将各个列转换为字符串,并根据需要进行修改,以创建可解析的单个字符串列。 我有大约20个数据集,每个大约35,000行。
样本数据:
a = ["2000"] * 100000
b = ["176"] * 100000
c = ["00:15","00:30","00:45","01:00"] * 25000
d = {"year":a,"DOY":b,"time":c}
df = pd.DataFrame(d)
df.head()
DOY time year
0 176 00:15 2000
1 176 00:30 2000
2 176 00:45 2000
3 176 01:00 2000
4 176 00:15 2000
我的慢速解决方案:
我创建了以下行以完成任务,但速度很慢 :
df["date"] = [df["year"][i]+"-"+df["DOY"][i]+" "+df["time"][i] for i in range(0,len(df),1)]
df.head()
DOY time year date
0 176 00:15 2000 2000-176 00:15
1 176 00:30 2000 2000-176 00:30
2 176 00:45 2000 2000-176 00:45
3 176 01:00 2000 2000-176 01:00
4 176 00:15 2000 2000-176 00:15
题:
for the purpose of parsing into datetime format? year
, DOY
和time
列的以将其解析为datetime格式的最快方法是什么? 还是这完全是错误的方法?
一如既往,感谢您的建议。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.