I'm trying to get the total number of books that an author wrote and put it in a column called book number with my dataframe that has 15 other columns.
I checked online and people use groupby with count(), however it doesn't create the column that I want, it only gives a column of numbers without a name and I can't put it together with the original dataframe.
author_count_df = (df_author["Name"]).groupby(df_author["Name"]).count()
print(author_count_df)
Result:
Name
A D 3
A Gill 4
A GOO 3
ALL SHOT 10
AMIT PATEL 5
..
vishal raina 7
walt walter 6
waqas alhafidh 3
yogesh koshal 8
zainab m.jawad 9
Name: Name, Length: 696, dtype: int64
Expected: A dataframe with
Name other 14 columns from author_df Book Number
A D ... 3
A Gill ... 4
A GOO ... 3
ALL SHOT ... 10
AMIT PATEL ... 5
... ..
vishal raina ... 7
walt walter ... 6
waqas alhafidh ... 3
yogesh koshal ... 8
zainab m.jawad ... 9