CSV file with multiples tables, how to get the middle table only
【Source】
【Problem】
I have a CSV file with multiples headers and tables which was created by our system. Number of rows are dynamics but the table title name is always the same. Between each table, there's a blank row. I'm using python3.7.3 and want to get the middle table(Device table) then upload to our database.
How can I do to get the middle table only? Can regex work with CSV file in this case?
Original file:
Report title:ABC
Created Date:Jul-15-2019
Model
Model Name,Number
abc,1
abc,2
Device
Device Name,Number
efg,1
efg,2
efg,3
Missing Device
Device Name,Number
xyz,3
xyz,4
The table I want to have(without table name):
Device Name,Number
efg,1
efg,2
efg,3
【Answer】
A |
B |
C |
|
1 |
=file("multiples-tables.csv").read@n() |
||
2 |
=create(DeviceName,Number) |
||
3 |
for A1.group@i(~=="") |
||
4 |
if A3.m(2)=="Device" |
||
5 |
=A3.to(4,) |
||
6 |
>C5.run(A2.insert(0,string(C5.~.array().m(1)),C5.~.array().m(2))) |
A1:Read in sequence by line
A2:Create sequence table
A3:Grouping in empty rows
B4:Determine whether the second item of the intra-group sequence is “Device”
C5:Interception of required data items
C6:Insert data item to order table
【Summary】
CSV files often contain a variety of table structures. How to quickly extract certain types of data, esProc gives a general and simple method. For more examples of processing, please refer to Qian College - esProc - text computing.
SPL Official Website 👉 https://www.scudata.com
SPL Feedback and Help 👉 https://www.reddit.com/r/esProc_SPL
SPL Learning Material 👉 https://c.scudata.com
SPL Source Code and Package 👉 https://github.com/SPLWare/esProc
Discord 👉 https://discord.gg/cFTcUNs7
Youtube 👉 https://www.youtube.com/@esProc_SPL