How to convert string to datetime format in parquet file format within parquet datastore?
조회 수: 21 (최근 30일)
이전 댓글 표시
The below is the sample parquet datastructure that i am using.
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/331775/image.png)
This is the structure of the data. Where both the date and time are in string format. This is the data that have been converted in csv to parquet. I have tried many times to convert second and third column into datetime format. So that I can write some query to operate/plot on perticular duration for analysis.
So the question is how to convert the string into second and third column into datetime format in parquet file format?
I am using Matlab 2020a.
Many Thanks in advance!
댓글 수: 0
채택된 답변
Stephen23
2020년 7월 15일
편집: Stephen23
2020년 7월 15일
>> D = {'2020/1/1' ;'2020/1/1' ;'2020/1/1' };
>> T = {'00:01:0:0';'00:01:0:60';'00:01:0:320'};
Method one: sscanf and duration:
>> M = sscanf(sprintf(' %s:',T{:}),'%f:',[4,Inf]).';
>> dt = datetime(D,'InputFormat','yyyy/M/d') + duration(M(:,1),M(:,2),M(:,3),M(:,4))
dt =
01-Jan-2020 00:01:00
01-Jan-2020 00:01:00
01-Jan-2020 00:01:00
>> dt.Second % check the milliseconds:
ans =
0
0.0600
0.3200
Method two: regexprep:
>> C = strcat(D,'@',regexprep(T,{':(\d)$',':(\d\d)$'},{':00$1',':0$1'}));
>> dt = datetime(C,'InputFormat','yyyy/M/d@H:m:s:SSS')
dt =
01-Jan-2020 00:01:00
01-Jan-2020 00:01:00
01-Jan-2020 00:01:00
>> dt.Second % check the milliseconds:
ans =
0
0.0600
0.3200
추가 답변 (0개)
참고 항목
카테고리
Help Center 및 File Exchange에서 Data Type Conversion에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!