I am trying to get part of a larger piece of code to work so have pulled out the problem element and created a mini code for testing.
import math
import csv
import pandas as pd
from pandas import DataFrame
print(df)
data= pd.read_csv('miniDF.csv')
df=pd.DataFrame(data, columns=['x'])
df['y']=(12.775*math.exp(-1.494*df['x']))
print(df)
The x column in the df are 0.01,0.1,0.5,1.5,2.9 Just simple float values that mimic my real DataFrame. If I give the equation a single 'x' value in the code, the maths works correctly, but it doesn't work when pulling x values from the DataFrame. The shell output and error I get is:
X
0 0.01
1 0.05
2 0.10
3 0.15
4 1.00
5 2.90
Traceback (most recent call last):
File "/Users/willhutchins/Desktop/minitest.py", line 11, in <module>
df['y']=(12.775*math.exp(-1.494*df['X']))
File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages/pandas/core/series.py", line 131, in wrapper
raise TypeError("cannot convert the series to " "{0}".format(str(converter)))
TypeError: cannot convert the series to <class 'float'>
Ultimately, I want to use it like this:
df['SBTn']=np.where(df['Fr']<=(12.775*math.exp(-1.494*(df['Fr']))),1,df['SBTn'])
Assuming the first question can be answered, does anybody foresee any problems using it in the np.where version?