0

I am new to pandas and I don't know how to word this question, but I need help on how to change a dataframe and reorganize it. I would like to minimize the large dataframe without having to manually input the data as shown in the img reference. I tried groupby() but it is not exactly what I am looking for because I also need to create 2 new columns based on the yes/no values in the existing PlayTennis column. Let me know. Thanks in advance.

See image for reference:

Img reference

GeX
  • 1

1 Answers1

1

I think you are trying to create a pivot table.

See if this code helps you out.

import pandas as pd
df = pd.DataFrame({"Outlook": ["Rainy", "Overcast", "Sunny"], "Tennis": ["No", "Yes", "Yes"]})
df["Count"] = [1]*df.shape[0]
df
pd.pivot_table(df, index=["Outlook","Tennis"], columns=["Tennis"], aggfunc=sum)

The result I get looks like this in my Jupyter notebook: table of results

fraz
  • 26
  • 4