How to readtable filtering columns and rows?
조회 수: 17 (최근 30일)
이전 댓글 표시
Hello,
Maybe someone knows if there is a way to readtable not only defining the column names but defining rows values as well? I have a *.csv file :
ReceivingDate ReceivingTime SecurityID Asset EntryType EntryPrice EntrySize
20180429 16:53:28.944250499 10062 FOB A 0 0
20180429 16:53:28.944250499 10062 FOB B 0.03125 5
20180429 16:53:33.913990105 10062 FOB A 0 0
20180429 16:53:33.913990105 10062 FOB B 0 0
20180429 16:53:41.173484956 10062 FOB A 0.03125 5
20180429 16:53:41.173484956 10062 FOB B 0 0
20180430 16:54:55.254652081 10062 FOB A 0.03125 5
20180430 16:54:55.254652081 10062 FOB B 0.078125 1
20180430 17:06:59.219609240 10062 FOB A 0.03125 5
20180430 17:06:59.219609240 10062 FOB B 0 1
20180430 17:11:55.316770824 10062 FOB A 0.03125 5
20180430 17:11:55.316770824 10062 FOB B 0.0078125 1
I use this code to define which columns to read:
opts = detectImportOptions('trys.csv');
opts.SelectedVariableNames = {'ReceivingDate','ReceivingTime','EntryType','EntryPrice'};
t = readtable('trys.csv',opts);
And the result is as follows:
ReceivingDate ReceivingTime EntryType EntryPrice
20180429 16:53:28.944250499 A 0
20180429 16:53:28.944250499 B 0.03125
20180429 16:53:33.913990105 A 0
20180429 16:53:33.913990105 B 0
20180429 16:53:41.173484956 A 0.03125
20180429 16:53:41.173484956 B 0
20180430 16:54:55.254652081 A 0.03125
20180430 16:54:55.254652081 B 0.078125
20180430 17:06:59.219609240 A 0.03125
20180430 17:06:59.219609240 B 0
20180430 17:11:55.316770824 A 0.03125
20180430 17:11:55.316770824 B 0.0078125
Would it be possible to filter row values (20180430), that final readtable result would be
ReceivingDate ReceivingTime EntryType EntryPrice
20180430 16:54:55.254652081 A 0.03125
20180430 16:54:55.254652081 B 0.078125
20180430 17:06:59.219609240 A 0.03125
20180430 17:06:59.219609240 B 0
20180430 17:11:55.316770824 A 0.03125
20180430 17:11:55.316770824 B 0.0078125
댓글 수: 0
채택된 답변
Jan
2018년 11월 16일
편집: Jan
2018년 11월 16일
There would not be a big advantage, if readtable filters the contents of the data already, because it has to read the complete file in any way. I'd prefer to let readtable read the complete file and to select the wanted data afterwards. Otherwise readtable becomes a multi-purpose function, a "one hammer hits all I need".
댓글 수: 2
Jan
2020년 12월 6일
A CSV file of many GB is a design error already. Human readable files are useful only, if they have to be read end edited by human. A "many GB" file is too large to do this. So a binary file is the better choice.
추가 답변 (0개)
참고 항목
카테고리
Help Center 및 File Exchange에서 Whos에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!