I am trying to expand the horizons of python and learn how to do something that is pretty simple to execute in Excel.
I have this data:
Group Function
1 A
1 B
1 C
2 A
2 C
3 C
3 A
3 D
4 E
And I would like a table that displays information in this format (executed using a pivot table in Excel with columns: function, rows: group, values: number of groups)
Function
Group A B C D E
1 1 1 1
2 1 1
3 1 1 1
4 1
I created a data framework and added a column as shown below:
df = pd.read_excel(filepath)
df['1']=1
print(df.groupby('GROUP'))
and
1) It does not recognize the Function field because dtype: object 2) It really does not fulfill the function I'm looking for, which makes me think that this is probably not the function I need. I also tried to work with various pivot_table iterations, but didn't seem to be able to get this to work.
Does anyone have any ideas? Thanks in advance.