pandas DataFrame, and plot summaries of the data using matplotlib and seaborn.
Get data from Granta MI
Connect to MI and specify a database.Use DataFrames to pre-process and append data
Build a separate DataFrame for each table
Create a DataFrame for each Granta MI table. The DataFrames are built from two separate lists of dictionaries:build_df that contains the build records. Set the DataFrame index to be the Build ID attribute value,
and sort by the index to guarantee a repeatable row order.
We use .dropna() to ensure that only fully populated records are kept in the dataframe.
| Travel Speed | |
|---|---|
| Build ID | |
| 2013-04-15 CLAD-2321 01 | 0.0086 |
| 2013-04-16 CLAD-2321 02 | 0.0096 |
| 2013-04-17 CLAD-2321 03 | 0.0106 |
| 2013-04-17 CLAD-2321 04 | 0.0116 |
| 2013-04-17 CLAD-2321 05 | 0.0126 |
tensile_df, that contains the tensile test results. Again, set the index to be the Build ID attribute value
and sort by both this index and the Specimen ID.
| Specimen ID | 0.2% Offset Yield Stress | Ultimate Tensile Strength | Specimen Orientation | |
|---|---|---|---|---|
| Build ID | ||||
| 2013-04-15 CLAD-2321 01 | L13L12AA11T | 127.300 | 126.81 | AT |
| 2013-04-15 CLAD-2321 01 | L13L12AA13T | 121.125 | 121.77 | LT |
| 2013-04-15 CLAD-2321 01 | L13L12AA15T | 121.315 | 124.47 | LT |
| 2013-04-15 CLAD-2321 01 | L13L12AA17T | 121.885 | 122.76 | LT |
| 2013-04-15 CLAD-2321 01 | L13L12AA1T | 126.730 | 130.32 | L |
Join the dataframes
Use thedataframe.join() method to create a DataFrame with both sets of data. The join type will default to left-join if not specified; this is fine in our example because the records were linked via a smart link in Granta MI, and so the set of indices is the same for both DataFrames.
| Travel Speed | Specimen ID | 0.2% Offset Yield Stress | Ultimate Tensile Strength | Specimen Orientation | |
|---|---|---|---|---|---|
| Build ID | |||||
| 2013-04-15 CLAD-2321 01 | 0.0086 | L13L12AA11T | 127.300 | 126.81 | AT |
| 2013-04-15 CLAD-2321 01 | 0.0086 | L13L12AA13T | 121.125 | 121.77 | LT |
| 2013-04-15 CLAD-2321 01 | 0.0086 | L13L12AA15T | 121.315 | 124.47 | LT |
| 2013-04-15 CLAD-2321 01 | 0.0086 | L13L12AA17T | 121.885 | 122.76 | LT |
| 2013-04-15 CLAD-2321 01 | 0.0086 | L13L12AA1T | 126.730 | 130.32 | L |
Refine the data
Extract simple numeric and string values from the MI Scripting Toolkit data types.| Travel Speed | 0.2% Offset Yield Stress | Ultimate Tensile Strength | Specimen Orientation | Specimen ID | |
|---|---|---|---|---|---|
| Build ID | |||||
| 2013-04-15 CLAD-2321 01 | 0.0086 | 127.300 | 126.81 | AT | L13L12AA11T |
| 2013-04-15 CLAD-2321 01 | 0.0086 | 121.125 | 121.77 | LT | L13L12AA13T |
| 2013-04-15 CLAD-2321 01 | 0.0086 | 121.315 | 124.47 | LT | L13L12AA15T |
| 2013-04-15 CLAD-2321 01 | 0.0086 | 121.885 | 122.76 | LT | L13L12AA17T |
| 2013-04-15 CLAD-2321 01 | 0.0086 | 126.730 | 130.32 | L | L13L12AA1T |
units dict so you can create plots with meaningful axis labels.
Plot the data
This code snippet is optional, and is included to increase the size of all plots generated in this notebook.Investigate the relationship between two properties
Create a scatter plot comparing Ultimate Tensile Strength of samples to the Travel Speed used during the build.


Investigate the impact of a third property
The orientation of each specimen during the test was also exported, but not included on the plots above. The simplest way to visualize this data is to add it to the original scatter plot as a color axis.
DataFrame.value_counts() method.
True or False values in rows_to_keep (set to True if the value is in the specified list). rows_to_keep is then passed as a selector into the DataFrame, which maps the list onto the DataFrame rows and returns a new DataFrame with only the True rows included.
| Travel Speed | 0.2% Offset Yield Stress | Ultimate Tensile Strength | Specimen Orientation | Specimen ID | |
|---|---|---|---|---|---|
| Build ID | |||||
| 2013-04-15 CLAD-2321 01 | 0.0086 | 121.125 | 121.77 | LT | L13L12AA13T |
| 2013-04-15 CLAD-2321 01 | 0.0086 | 121.315 | 124.47 | LT | L13L12AA15T |
| 2013-04-15 CLAD-2321 01 | 0.0086 | 121.885 | 122.76 | LT | L13L12AA17T |
| 2013-04-15 CLAD-2321 01 | 0.0086 | 126.730 | 130.32 | L | L13L12AA1T |
| 2013-04-15 CLAD-2321 01 | 0.0086 | 126.065 | 125.37 | L | L13L12AA3T |
.value_counts() from before to confirm the change was successful.
split=True in the sns.violinplot constructor to show the two distributions side-by-side. The dependence
on Specimen Orientation is now much clearer.
