- is detected as text by the detectImportOptions function, and
- the uniqueness of the text in that column is below a threshold, in which case, using a categorical value may be a better option for the user.
Why does the datatype automatically change to categorical while importing a spreadsheet?
조회 수: 5 (최근 30일)
이전 댓글 표시
MathWorks Support Team
2020년 7월 31일
답변: MathWorks Support Team
2020년 7월 31일
While importing a spreadsheet using the Import Tool, the datatype of all the columns in the spreadsheet changed to "categorical". Why does this happen?
채택된 답변
MathWorks Support Team
2020년 7월 31일
In the Import Tool, a column of data is interpreted as categorical if it:
If the spreadsheet contains dashes or any such characters in cells as a placeholder for empty cell, it causes the data type detection to treat the column as text. You can observe this at the command line by executing the following commands to the attached spreadsheet "Book1.xlsx":
>> opts = detectImportOptions("Book1.xlsx");
>> opts.VariableTypes
ans =
1×10 cell array
{'char'} {'char'} {'char'} {'char'} {'char'} {'char'} {'char'} {'char'} {'char'} {'char'}
A workaround for this is to force these columns to be numeric. For example:
>> opts = detectImportOptions("Book1.xlsx");
>> opts = setvartype(opts, "double");
>> t = readtable("Book1.xlsx", opts);
댓글 수: 0
추가 답변 (0개)
참고 항목
카테고리
Help Center 및 File Exchange에서 Spreadsheets에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!