擅长:python、mysql、java
<p>我建议如下:</p>
<pre><code>import pandas as pd
# create the three dataframes
month_data = pd.DataFrame({'day_of_month':pd.date_range('01/01/2021','31/01/2021')})
student_df = pd.DataFrame({'day_of_month':pd.date_range('01/15/2021','31/01/2021')})
final_df = month_data
# apply if statement to the dataframe
# the value 'present' will be assigned to all the rows where month_data has a date that is also present in the student_df.
final_df.loc[month_data['day_of_month'].isin(student_df['day_of_month']), 'attendence'] = 'present'
# previous line will place a NaN in all other locations. The next line will replace all the NaNs by `absent`
final_df.loc[final_df['attendence'] != 'present', 'attendence'] = 'absent'
</code></pre>