Skip to content
Snippets Groups Projects

Updating the csv readers

Merged Andrew Maclean requested to merge Updating-the-CSV-readers into master
7 files
+ 54
59
Compare changes
  • Side-by-side
  • Inline
Files
7
### Description
This example creates a PolyData object containing lines and points from a CSV file and writes it to a .vtp file.
This example loads a CSV file, edits it and visualises the result.
It demonstrates the use of [pandas](https://pandas.pydata.org/) to read the CSV input file and then using [numpy](https://numpy.org/) and the vtk-numpy interface for building the resultant vtkPolyData object based on the options selected.
It demonstrates the use of [pandas](https://pandas.pydata.org/) to read and edit the CSV input file, then use [numpy](https://numpy.org/) and the vtk-numpy interface for building the resultant vtkPolyData object based on the options selected.
The key thing about `pandas` is it can read/write data in various formats: CSV and text files, Microsoft Excel, SQL databases, and the fast HDF5 format. It is highly optimized for performance and the DataFrame object allows for extensive row/column manipulation. So we can edit the data, creating new columns, and, finally, selecting only relevant columns for further analysis by VTK.
The key thing about `pandas` is it can read/write data in various formats: CSV and text files, Microsoft Excel, SQL databases, and the fast HDF5 format. It is highly optimized for performance and the DataFrame object allows for extensive row/column manipulation. So we can edit the data, creating new columns, and, finally, select only relevant columns for further analysis by VTK.
In this case we select columns using numpy to create the three-dimensional point data array data. The numpy objects are then converted to vtk data structures and integrated into a vtkPolyData object.
Loading