How to readtable filtering columns and rows?
33 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
Mantas Vaitonis
el 16 de Nov. de 2018
Comentada: Jan
el 6 de Dic. de 2020
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 comentarios
Respuesta aceptada
Jan
el 16 de Nov. de 2018
Editada: Jan
el 16 de Nov. de 2018
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 comentarios
Jan
el 6 de Dic. de 2020
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.
Más respuestas (0)
Ver también
Categorías
Más información sobre Whos en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!