I tried looking for an answer but couldn't find it. If someone has a link, all the better. My question goes as follows.
- I have a sheet I am reading in pandas which has numerous columns with values in it.
- There are three calculations I need to run which use bits from different columns at a time.
- I need to return the max of those calculations in one bit of code, which will then be added to a new column.
I'm having problems with number 2.
Here is what my code would look like.
df = read_csv('file.csv')
df['Get New'] = maximum(df[Long] - df[Short], df[Long] + df[Short], df[Long] / df[Short])
df.to_csv('newFile.csv', index=False)
I know maximum doesn't work in this scenario but I can't seem to find what would. Any help is appreciated. Thanks!
EDIT: Here is the solve.
df['Get New'] = np.maximum(df['Long'] - df['Short'], df['Long'] + df['Short'])
df['Get New'] = np.maximum(df['Get New'], df['Long'] / df['Short'])