Hi everyone,
I am writing a bit of code whose purpose, essentially, is to take a data set (density varying with 10 different temperatures) from a CSV file using Pandas and to then polyfit the data to either cubic or quadratic form. Then define a function that returns the density for any given temperature within the range by using the coefficients obtained from the polyfit and then plot a smooth curve for density variation with temperature by adding many more additional points to the plot.
I have been able to read the data set and recall it using pandas and iloc function, however whenever I try and run the code past this stage, the program gives me the error below:
I am writing a bit of code whose purpose, essentially, is to take a data set (density varying with 10 different temperatures) from a CSV file using Pandas and to then polyfit the data to either cubic or quadratic form. Then define a function that returns the density for any given temperature within the range by using the coefficients obtained from the polyfit and then plot a smooth curve for density variation with temperature by adding many more additional points to the plot.
I have been able to read the data set and recall it using pandas and iloc function, however whenever I try and run the code past this stage, the program gives me the error below:
Error:Traceback (most recent call last):
File "/Users/tobyhallitt/Documents/Code/Individual Design/Thermophysical Properties/density.py", line 19, in <module>
d = polyfit(T_d, dens, 3)
File "<__array_function__ internals>", line 5, in polyfit
File "/Users/tobyhallitt/Documents/Code/Individual Design/Thermophysical Properties/.venv/lib/python3.8/site-packages/numpy/lib/polynomial.py", line 592, in polyfit
x = NX.asarray(x) + 0.0
TypeError: can only concatenate str (not "float") to str
I have tried troubleshooting myself but can't find a solution, if anyone could please help me out that would be very much appreciated. My code current is presented below (using Visual Studio Code):### 16 / 04 / 2020 ### Toby Hallitt ### Density property calculation for shell side fluid # Import Pandas import pandas as pd # Import matplot and numpy import matplotlib.pyplot as plt from numpy import polyfit from numpy import linspace # Read Aspen Plus properties CSV file data = pd.read_csv("denref.csv") # Locate temperature and density variables and polyfit to find polynomial coefficients T_d = data.iloc[2:12,0] dens = data.iloc[2:12,2] d = polyfit(T_d, dens, 3) # Define function used to find density at given temperature def density(T): """Outputs density as a polynomial function of a given temperature""" return ((d[0]) * (T**3)) + ((d[1]) * (T**2)) + ((d[2]) * T) + (d[3]) # Create additional temperature points for the curve Tt = linspace(290.15, 340.15, 20) # Calculate volumetric flow for every point on the curve mass_flow = 0.03639 # kg s^-1 volumetric_flow = [mass_flow/density(t) for t in Tt] print(volumetric_flow) #####################Please contact me if you have any questions. Thanks in advance!