The date format from my readtable is wrong so I get "NaT"
조회 수: 12 (최근 30일)
이전 댓글 표시
I really can't believe this was never asked after I googled for hours.
I have a REALLY long csv file with about 1million rows with dates. The format they were written is 'dd/MM/yyyy hh:mm:ss'.
When I try to import those values I keep getting "NaT" on dates like the 31st of october. It's obvious that MATLAB is trying to read on format 'MM/dd/yyyy' instead of 'dd/MM/yyyy'.
I've seen another posts about people that change formats after they imported the data so it would be really easy, but it's not the case.
I've changed the date format on "Preferences->Command Window' but I keep getting frustrated with 'NaT' on half of the data.
I've thought about two options:
- changing the format of readtable (which I tried that already doing something like a=readtable(file,'Range','e5:e931478','DatetimeType','dd/mm/yyyy hh:mm'); but it says
"Error using readtable (line 318)
Expected input to match one of these values:
'datetime', 'text', 'exceldatenum'
The input, 'dd/mm/yyyy hh:mm', did not match any of the valid values."
- The other thing I could try is to import the dates as another format like texst char or strings and THEN try to read them.
I'm really desperate here can anyone help ?
a=readtable(file,'Range','e5:e931478','DatetimeType','dd/mm/yyyy hh:mm');
댓글 수: 3
Qiurui Zhu
2022년 7월 25일
But I have not import the data yet. How do I let it recognize the var name in the "setvaropts(var,'InputFormat','dd/MM/yyyy hh:mm')" command. In my case, the error is "Unrecognized function or variable 'TIMESTAMP'."
Walter Roberson
2022년 7월 25일
opt = detectImportOptions(file);
opt = setvaropt(opt, 'TIMESTAMP', 'InputFormat', 'dd/MM/yyyy hh:mm');
tData = readtable(file, opt);
답변 (0개)
참고 항목
카테고리
Help Center 및 File Exchange에서 Calendar에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!