You could use pandas.factorize:
In [32]: s = pd.Series(['a','b','c'])
In [33]: labels, levels = pd.factorize(s)
In [35]: labels
Out[35]: array([0, 1, 2])
More Related Contents:
- converting a text file to csv file with out index
- Get the row(s) which have the max value in groups using groupby
- Error: pandas hashtable keyerror
- Writing a pandas DataFrame to CSV file
- Remove unwanted parts from strings in a column
- pandas: How do I split text in a column into multiple rows?
- Find row where values for column is maximal in a pandas DataFrame
- How to filter rows containing a string pattern from a Pandas dataframe [duplicate]
- python/pandas: convert month int to month name
- How to check if a column exists in Pandas
- How to form tuple column from two columns in Pandas
- Convert pandas Series to DataFrame
- How to plot stacked event duration (Gantt Charts)
- Pandas still getting SettingWithCopyWarning even after using .loc
- Print very long string completely in pandas dataframe
- pandas comparison raises TypeError: cannot compare a dtyped [float64] array with a scalar of type [bool]
- How do I filter a pandas DataFrame based on value counts?
- Lambda including if…elif…else
- Pandas query function not working with spaces in column names
- Create bool mask from filter results in Pandas [duplicate]
- Getting a list of indices where pandas boolean series is True
- Pandas DataFrame sort by categorical column but by specific class ordering
- How can I remove extra whitespace from strings when parsing a csv file in Pandas?
- convert entire pandas dataframe to integers in pandas (0.17.0)
- Remove NaN values from pandas dataframe and reshape table [duplicate]
- Pandas groupby and aggregation output should include all the original columns (including the ones not aggregated on)
- Merging two tables with millions of rows in Python
- Selecting a range of columns in a dataframe
- Pandas data frame to dictionary of lists
- Pandas min() of selected row and columns