Pandas, adjusting the height of a column header?
Try:
df = frame.pivot(
index=["FirstName", "LastName", "Building"],
columns="Month",
values="Sales",
).rename_axis(columns=None).reset_index()
Output:
>>> df
FirstName LastName Building December November
0 Jack Yellow Building2 150 275
1 Jill Green Building1 150 150
2 John Blue Building1 200 100
Update
Suppose the following dataframe:
>>> df
FirstName LastName Building December November
0 Jack Yellow Building2 150 275
1 Jack Yellow Building1 125 175
2 John Blue Building 200 100
You can do something like this:
df.loc[df['FirstName'].eq(df['FirstName'].shift()), 'FirstName'] = ''
print(df)
# Output
FirstName LastName Building December November
0 Jack Yellow Building2 150 275
1 Yellow Building1 125 175
2 John Blue Building 200 100
I checked if the first name of current row is the same than the previous one. If yes, I replace the first name by ''
. So when (index 1, Jack) == (index 0, Jack)
, I set (index 1, Jack)
to ''