How to specify the column headers while reading in a CSV file using 'readtable'?
조회 수: 49 (최근 30일)
이전 댓글 표시
MathWorks Support Team
2019년 7월 25일
편집: MathWorks Support Team
2024년 8월 29일
I am reading in a CSV file using 'readtable', but I have my column headers in row 4 of the CSV file. How do I specify the column headers?
채택된 답변
MathWorks Support Team
2024년 7월 29일
편집: MathWorks Support Team
2024년 8월 29일
The 'VariableNamesLine' property can be used to specify this. Please refer to the example snippet below.
%Import the options of the csv file
opts=detectImportOptions('sample.csv');
%Defines the row location of channel variable name
opts.VariableNamesLine = 4;
%Specifies that the data is comma seperated
opts.Delimiter =','; %Specifies that the data is comma seperated
%Read the table
t = readtable('sample.csv',opts, 'ReadVariableNames', true);
The properties 'VariableNamesRange' and 'VariableNamesLine' can be specified only if the 'ReadVariableNames' argument is set to 'true'.
Refer to the second subsection of 'Name-Value Pair Arguments' to learn more. To access release specific documentation in MATLAB R2019a, please run the following command in the MATLAB command window:
>> web(fullfile(docroot, 'matlab/ref/readtable.html'))
Please follow the below link to search for the required information regarding the current release:
댓글 수: 0
추가 답변 (0개)
참고 항목
카테고리
Help Center 및 File Exchange에서 Text Files에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!