Search
 
SCRIPT & CODE EXAMPLE
 

PYTHON

how to convert each string to a category or int in python dataframe

In [3]: df = pd.DataFrame({"A": ["a", "b", "c", "a"]})

In [4]: df["B"] = df["A"].astype('category')

In [5]: df
Out[5]: 
   A  B
0  a  a
1  b  b
2  c  c
3  a  a
Comment

PREVIOUS NEXT
Code Example
Python :: How to Merge train and Test dataset in python 
Python :: seir model python 
Python :: labs fill ggplot2 
Python :: how to check substring in python 
Python :: python while true loop 
Python :: pandas data frame to list 
Python :: pandas nan values in column 
Python :: print inline output in python 
Python :: pandas swapaxes example 
Python :: open excel through python 
Python :: Matplotlib rotated xticklabels 
Python :: distplot in python 
Python :: assert python 
Python :: howe to print all values and keysin d 
Python :: convert timedelta to days 
Python :: pandas xa0 
Python :: python pandas get labels 
Python :: bytearray to hex python 
Python :: get keys from dictionary python 
Python :: python get desktop environment 
Python :: python return using if 
Python :: reverse a string python 
Python :: replace word in column pandas lambda 
Python :: how to get any letter of a string python 
Python :: find all indices of element in string python 
Python :: pathlib path of current file 
Python :: how to write variables in python 
Python :: link in embed discord.py 
Python :: how to bold in colorama 
Python :: json and python login system 
ADD CONTENT
Topic
Content
Source link
Name
5+7 =