I think there is a nice way to combine the solution of @chrisb and @CodeShaman (As it was pointed out CodeShamans solution counts total and not consecutive values).
df['count'] = df.groupby((df['col'] != df['col'].shift(1)).cumsum()).cumcount()+1
col count
0 B 1
1 B 2
2 A 1
3 A 2
4 A 3
5 B 1
Related Contents:
- Filter dataframe rows if value in column is in a set list of values [duplicate]
- Convert DataFrame column type from string to datetime
- How to select rows with one or more nulls from a pandas DataFrame without listing columns explicitly?
- Progress indicator during pandas operations
- Merge two dataframes by index
- How can I map True/False to 1/0 in a Pandas DataFrame?
- pandas get column average/mean
- check if variable is dataframe
- How to add value labels on a bar chart
- Are for-loops in pandas really bad? When should I care?
- How do I create a new column from the output of pandas groupby().sum()?
- Pandas groupby: How to get a union of strings
- How to use sklearn fit_transform with pandas and return dataframe instead of numpy array?
- pandas – add new column to dataframe from dictionary [duplicate]
- how to test if a variable is pd.NaT?
- Apply Function on DataFrame Index
- How to print a specific row of a pandas DataFrame?
- Lambda including if…elif…else
- Is there a way to copy only the structure (not the data) of a Pandas DataFrame?
- How can I compute a histogram (frequency table) for a single Series?
- Pandas read_sql with parameters
- List of Tuples to DataFrame Conversion [duplicate]
- Pandas concat yields ValueError: Plan shapes are not aligned
- ValueError: Grouper for not 1-dimensional
- How to sort pandas data frame using values from several columns?
- HDF5 – concurrency, compression & I/O performance [closed]
- Is it possible to append Series to rows of DataFrame without making a list first?
- Generating random dates within a given range in pandas
- How do I round datetime column to nearest quarter hour
- Pandas: Converting to numeric, creating NaNs when necessary
- Creating Pandas Dataframe between two Numpy arrays, then draw scatter plot
- Loading a .rds file in Pandas
- forward fill specific columns in pandas dataframe
- Normalize rows of pandas data frame by their sums [duplicate]
- Solution for SpecificationError: nested renamer is not supported while agg() along with groupby()
- Fast Haversine Approximation (Python/Pandas)
- Trying to remove commas and dollars signs with Pandas in Python
- How to preview a part of a large pandas DataFrame, in iPython notebook?
- AttributeError: Can’t get attribute ‘new_block’ on
- How does one insert statistical annotations (stars or p-values)
- Pandas printing ALL dtypes
- How to create a stacked bar chart for my DataFrame using seaborn [duplicate]
- ValueError: cannot insert ID, already exists
- Apply StandardScaler to parts of a data set [duplicate]
- Filter out groups with a length equal to one
- How to translate “bytes” objects into literal strings in pandas Dataframe, Python3.x?
- Plot a bar plot from a Pandas DataFrame
- vectorize conditional assignment in pandas dataframe
- How to convert JSON data inside a pandas column into new columns
- How to group and count rows by month and year using Pandas?