PythonBridge custom views for pandas DataFrame and Series

One of the most well know Python libraries is pandas, a data analysis and manipulation tool.

The following Python source code file adds a number of remote Phlow views for the main DataFrame and Series classes.

This page explains the fast way to get started, as a user of this feature. To learn more about the internals, consult Adding gtViews to the existing Python pandas DataFrame and Series class.

The file location is defined next, inspect it to see the contents.

pandasViews := FileLocator gtResource / 'feenkcom' / 'gt4python' / 'data' / 'python' / 'view_pandas.py'
  

Given the path above, we can load the code programmatically into the global PBApplication instance (which should already be running with pandas installed).

When necessary:

PBApplication isRunning ifFalse: [ PBApplication start ].
PBApplication uniqueInstance installModule: 'pandas'.
  
PBApplication do: [ :application | 
	application newCommandStringFactory
		script: pandasViews contents;
		sendAndWait ]
  

You can test the views by loading and inspecting a DataFrame from an example CSV file.

moviesCsvPath := FileLocator gtResource / 'feenkcom' / 'gtoolkit-demos' / 'data' / 'imdb' / 'Movies.csv'
  
moviesCsvPathString := moviesCsvPath resolve pathString
  
pandas.read_csv(moviesCsvPathString)