8. More Practice#
Learning Objectives
Be able to:
Read an excel file into a pandas dataframe
Check and correct column data types in a dataframe
Drop columns containing no data i.e. NaN
Drop rows with missing values
Add new columns to the dataframe
Select data based on the values in one of the columns
Plot the data using matplotlib.pyplot
Perform a non-linear fit to the data using scipy.optimize.curve_fit and interpret the results
Applications:
Energy between two atoms versus separation distance (Callister, Chapter 2 Bonding)
Elastic modulus of tubular shaft in bending (Callister, 9th ed. Example 16.1)
Concrete data set (“github.com/maajdl/Yeh-concrete-data-sklearn”)
Date files needed:
import numpy as np
import matplotlib.pyplot as plt
import pandas as pd
from pathlib import Path
from scipy.optimize import curve_fit
8.1. Exercises#
8.1.1. Problem 1#
Using pandas, read the data file 06_Tafel_data.xlsx into a variable called ‘raw_data’.
(a) execute raw_data.iloc[2:7,1:3]
and then
(b) explain in plain language what the above command did. Comment on how .iloc[]
differs from .loc[]
(c) write the equivalent command as in (a) but now using .loc[]
rather than .iloc[]
8.1.2. Problem 2#
(a) Plot the data in the file 08_bond_energy_data.xlsx and (b) Find the best fit to the data using the function:
def bondEnergy(r, A, B, n):
(c) Use the pandas function .min()
to find the equilibrium bond energy, \(E_0\), and then the corresponding equilibrium atom spacing, \(r_0\). Add a horizontal and vertical line to your plot at these values, respectively.
8.1.3. Problem 3#
(a) The longitudinal modulus of elasticity of a tubular shaft measured in bending is given by:
def mod(F,L,Δy,d_o,d_i):
) to calculate the longitudinal modulus of elasticity. Calculate the longitudinal modulus of elasticity. Use print with an f-string to include the units with your answer and limit your answer to 2 decimals.
(b) Write a function for the beam deflection starting with def deflec(di,do,L,F, E):
. For the same setup as above if the modulus is 200 GPa, plot the deflection, \(\Delta y\), as a function of the inner diameter where \(20\ mm \leq d_i \leq 60\ mm\). Make sure you label your axes. Use small blue points.
8.1.4. Problem 4#
Read the data file: 08_concrete_data_Yeh.csv
Find the density of each concrete sample by adding together the data: cement, slag, flyash, water, superplasticizer, courseaggregate, and fineaggregate.
Plot the compressive strength vs age for the concrete samples that have a density between 2450 and 2452.5. Label your axes and use green points.