I have a dataframe that looks like this:
Person Day Value
1 Mon 32
1 Tue 30
1 Wed 34
1 Thu 22
1 Fri 43
2 Mon 22
2 Wed 14
2 Fri 11
3 Tue 13
3 Wed 22
3 Thu 23
The dataset looks at value for every weekday (Mon-Fri) for a group of people. Some people have the full 5 days (e.g. person 1), some people only have a few days. I would like to create new empty rows so that everyone has the full 5 days even if they don't have a value.
This is the output I would like:
Person Day Value
1 Mon 32
1 Tue 30
1 Wed 34
1 Thu 22
1 Fri 43
2 Mon 22
2 Tue Nan
2 Wed 14
2 Thu Nan
2 Fri 11
3 Mon Nan
3 Tue 13
3 Wed 22
3 Thu 23
3 Fri Nan
I've tried to write something, but I can't figure out how to have it iterate through each person properly:
days = ['mon','tue','wed','thu','fri']
def normalise(person):
newperson = pd.DataFrame()
for day in days:
if day in person:
newperson[day] = days
else:
newperson[day] = np.nan
return newperson
normalised = normalise(df)
This just generates the days but with no other value contained. The actual dataset has around 200,000 people. Any ideas would be great, thanks!