import pandas as pd
import numpy as np
my_data = pd.read_excel('D:\\rent-calculation.xlsx')
print(my_data.columns)
print(my_data['dept'].value_counts())
print(my_data[my_data['id'].isnull()])
my_data['ck_date'] = pd.to_datetime(my_data['ck_date'])
bd=pd.to_datetime('2020-06-01') # base date
my_data['diff_days']=bd-my_data['ck_date']
print(my_data)
my_data['diff_days'] = my_data['diff_days']/ np.timedelta64(1, 'D')
print(my_data[my_data['diff_days'] > 200])
#my_data['allowed']=my_data['dept'].apply(lambda x:50 if x=="mktg" else np.nan)
#my_data['allowed']=my_data['dept'].apply(lambda x:65 if x=="production" else np.nan)
#my_data['allowed']=my_data['dept'].apply(lambda x:45 if x=="planning" else np.nan)
my_data['allowed']=np.where(my_data['dept']=='mktg',50,
np.where(my_data['dept']=='production',65,
np.where(my_data['dept']=='planning',45,np.nan)))
print(my_data)
print(my_data[my_data['diff_days'] > my_data['allowed']])
Author & Instructor at plus2net
I write and maintain practical tutorials on Python, PHP, SQL, JavaScript, HTML, jQuery, and web development at plus2net. The tutorials focus on clear explanations, working examples, and code that readers can test and adapt while learning.