Data analysis with python and Pandas - Convert String Category to Numeric Values Tutorial 6
Hi Guys checkout my udemy course at just 9.99$ https://www.udemy.com/data-science-with-python-and-pandas/?couponCode=KNOWLEDGE_IS_POWER https://www.udemy.com/manipulate-excel-file-from-python-openpyxl/?couponCode=KNOWLEDGE_IS_POWER https://www.udemy.com/learn-docker-from-scratch/?couponCode=KNOWLEDGE_IS_POWER https://www.udemy.com/learn-in-memory-database-redis-from-scratch/?couponCode=KNOWLEDGE_IS_POWER https://www.udemy.com/learn-event-processing-with-logstash-elk-stack/?couponCode=KNOWLEDGE_IS_POWER https://www.udemy.com/machine-learning-and-bigdata-analysis-with-apache-spark-python-pyspark/?couponCode=KNOWLEDGEISPOWER https://www.udemy.com/data-science-and-machine-learning-in-r-programming/?couponCode=KNOWLEDGE_IS_POWER Visit complete course on Data Science with Python : https://www.udemy.com/data-science-with-python-and-pandas/?couponCode=YTSOCIAL090 For All other visit my udemy profile at : https://www.udemy.com/user/ankitmistry/ This video will explain how to convert String categorical values to numerical values with apply function in pandas. import pandas as pd data = {'Id_Student' : [1,2,3,4,5,6,7,8,9,10],'Mathscore' :['Strong','Weak','Weak','Strong','Strong','Weak','Strong','Strong','Weak','Strong']} df = pd.DataFrame(data) df # # Strong = 1 and Weak =0 def tran_mathscore(x): if x == 'Strong': return 1 if x == 'Weak': return 0 df['Trans_MathScore'] = df['Mathscore'].apply(tran_mathscore) df
Download
0 formatsNo download links available.