<p>您可以创建一个新的数据框,其中包含所有日期以及每个学生在每个日期的名称:</p>
<p><strong>输入</strong></p>
<pre><code>#df1
day_of_month
0 2021-01-01
1 2021-01-02
2 2021-01-03
3 2021-01-04
4 2021-01-05
5 2021-01-06
6 2021-01-07
#df2
student_data attendence day_of_month
0 marcus present 2021-01-01
1 marcus present 2021-01-03
2 paul present 2021-01-04
</code></pre>
<p><strong>代码</strong></p>
<pre><code>students = df2['student_data'].unique().tolist()
df = pd.concat([df1.assign(student_data = name) for name in students])
df = df.merge(df2, on=['day_of_month', 'student_data'], how='left')
df['attendence'] = df['attendence'].fillna('absent')
</code></pre>
<p><strong>输出</strong></p>
<pre><code> day_of_month student_data attendence
0 2021-01-01 marcus present
1 2021-01-02 marcus absent
2 2021-01-03 marcus present
3 2021-01-04 marcus absent
4 2021-01-05 marcus absent
5 2021-01-06 marcus absent
6 2021-01-07 marcus absent
7 2021-01-01 paul absent
8 2021-01-02 paul absent
9 2021-01-03 paul absent
10 2021-01-04 paul present
11 2021-01-05 paul absent
12 2021-01-06 paul absent
13 2021-01-07 paul absent
</code></pre>