How to readtable filtering columns and rows?

37 次查看(过去 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

采纳的回答

Jan
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 个评论
Jorge Filipe
Jorge Filipe 2020-12-6
When you have an huge csv of many GB, that is not an option.
Jan
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 CenterFile Exchange 中查找有关 Whos 的更多信息

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by