python pandas use 2 colums for calc

In this example, I need to use 2 columns to in a calculation

df['diff']=df.apply(calc_diff, axis=1)

df['eff']=df.apply(calc,axis=1)

import pandas as pd
from math import degrees, sin,cos, radians
%matplotlib inline

data={}
for n in range(180):
    a=n%90
    if n>90:
        a*=-1
    data[n]={'id':n,'angle':a}

df=pd.DataFrame.from_dict(data,orient='index')
df['sun_angle']=45
df['eff']=0


#df['Value'] = df.apply(lambda row: my_test(row['a'], row['c']), axis=1)
#
#def my_test2(row):
#....:     return row['a'] % row['c']
#
#df['Value'] = df.apply(my_test2, axis=1)

def calc_diff(row):
    return abs(row['angle']-row['sun_angle'])

def calc(row):
    if abs(row['angle']-row['sun_angle'])>90:
        return 0
    else:
        if row['angle']==row['sun_angle']:
            return 1
        else:
            dif=abs(row['angle']-row['sun_angle'])

        return cos(radians(abs(row['angle']-row['sun_angle'])))

df['diff'] =df.apply(calc_diff, axis=1)
df['eff']  =df.apply(calc,axis=1)

#set all  less90 rows with a value of 0 to eff value of 0
#df.loc[df.less90==0,'eff'] = 0

df.plot('id','eff')

The output is a nice Cosine graph.

Example 2

Instead of using the whole Row ... As I have generated the Columns, and the storage Column. I just used them.

Note use of a seperate array so the plot is simplified.

%matplotlib inline
from  datetime import datetime, timedelta
from pytz import timezone
import pandas as pd
import ephem
from math import degrees, cos, radians
import arrow

fmt    = "%Y-%m-%d %H:%M:%S %Z%z"
fmt_HR = "%H:%M:%S"

#Telepayong

obs = ephem.Observer()
obs.lat = '15:20'
obs.long = '120:40'
sun_data={}
print("Jan 1st 2019")
#Make timezone aware
date = datetime(2019, 1, 1, 0, 0, 0, tzinfo=timezone('Asia/Manila'))
#For a year, per week
for day in range(1,366*24,1):
     newday = date + timedelta(hours=day)
     newday=newday.astimezone(timezone('Asia/Manila'))
     obsday=newday.astimezone(timezone('UTC'))
     obs.date = obsday
     sun = ephem.Sun(obs)
     sun.compute(obs) 
     #Convert to Local times
     utc_rise=datetime.strptime(str(sun.rise_time)+" UTC","%Y/%m/%d %H:%M:%S %Z").astimezone(timezone('UTC'))
     pi_rise=utc_rise.astimezone(timezone('Asia/Manila'))
     utc_set=datetime.strptime(str(sun.set_time)+" UTC","%Y/%m/%d %H:%M:%S %Z").astimezone(timezone('UTC'))
     pi_set=utc_rise.astimezone(timezone('Asia/Manila'))

     sun_data[newday.strftime(fmt)]={"rise":degrees(sun.rise_az),
                                                              "set":degrees(sun.set_az),
                                                              "rise_time":pi_rise.strftime(fmt_HR),
                                                              "set_time":pi_set.strftime(fmt_HR),
                                                              "sun_angle":degrees(sun.az)
                                                              }
df_sun_data=pd.DataFrame.from_dict(sun_data,orient='index')

def calc_2(solar_angle,sun_angle):
    if solar_angle>0 and solar_angle < 180:

        for sa in range(0,180,5):
            if abs(solar_angle-sun_angle)>90:
                return 0.0
            else:
                if solar_angle==sun_angle:
                    return 1.0
                else:
                    dif=abs(solar_angle-sun_angle)
                    return (cos(radians(abs(solar_angle-sun_angle))))
    else:
        return 0

#Create the New Columns for Calcs
cols=[]
filter=""
for a in range(0,90,10):
    a_str="Angle_{}".format(a)
    e_str="Eff_{}".format(a)
    df_sun_data[a_str]=a
    df_sun_data[e_str]=0
    df_sun_data[e_str] = df_sun_data.apply(lambda row: calc_2(row[a_str], row['sun_angle']), axis=1)
    print("Calculated Angle {}".format(a))
    cols.append(e_str)

df_sun_data['loc']=0
df_sun_data.index=pd.DatetimeIndex(df_sun_data.index)
#week_res=df_sun_data.groupby('loc').resample('W')[','.join(cols)].mean()

week_res=df_sun_data.groupby('loc').resample('W')[cols].mean()

week_res.plot()