You can use this:
df = df.groupby(['Symbol','Year']).count().unstack(fill_value=0).stack()
print (df)
Output:
Action
Symbol Year
AAPL 2001 2
2002 0
BAC 2001 0
2002 2
More Related Contents:
- How do I Pandas group-by to get sum?
- Get statistics for each group (such as count, mean, etc) using pandas GroupBy?
- How to groupby consecutive values in pandas DataFrame
- Python: get a frequency count based on two columns (variables) in pandas dataframe some row appers
- Pandas dataframe get first row of each group
- Pandas groupby multiple fields then diff
- How to access pandas groupby dataframe by key
- Python Pandas How to assign groupby operation results back to columns in parent dataframe?
- How can I use cumsum within a group in Pandas?
- pandas – find first occurrence
- Add a sequential counter column on groups to a pandas dataframe
- Group dataframe and get sum AND count?
- pandas divide row value by aggregated sum with a condition set by other cell
- Select row by max value in group in a pandas dataframe
- Pandas groupby with bin counts
- get first and last values in a groupby
- Pandas groupby and aggregation output should include all the original columns (including the ones not aggregated on)
- how to convert monthly data to quarterly in pandas
- Get the row corresponding to the max in pandas GroupBy [duplicate]
- Get frequency of item occurrences in a column as percentage [duplicate]
- How to get number of groups in a groupby object in pandas?
- How to change column names from numbers to names [closed]
- How to test if a string contains one of the substrings in a list, in pandas?
- How to convert index of a pandas dataframe into a column
- Pandas split DataFrame by column value
- NLTK-based text processing with pandas
- Convert list into a pandas dataframe
- Python: How to drop a row whose particular column is empty/NaN?
- Combine Pandas data frame column values into new column
- Python Pandas : pandas.to_datetime() is switching day & month when day is less than 13