How to handle data type conversation in python?

62 views Asked by At

I am doing the data segmentation using python for some csv data. I have below columns like Actionid, name, title. The data in given column is like;

enter image description here

Currently I am getting below error

enter image description here

My code is ;

import pandas as pd # for dataframes
import matplotlib.pyplot as plt # for plotting graphs
import seaborn as sns # for plotting graphs
import datetime as dt

data = pd.read_csv("Mydata.csv")
#pd.set_option("display.max_rows", None, "display.max_columns", None)

##print (data.head())
##print (data.tail())
##print (filtered_data.Country.value_counts()[:10].plot(kind='bar'))

plt.figure(1, figsize=(15, 6))
n=0

for x in ['actionId','name', 'title']:
    n += 1
    plt.subplot(1,3,n)
    plt.subplots_adjust(hspace=0.5, wspace=0.5)
    sns.distplot(data[x], bins=20)
    plt.title('Displot of {}'.format(x))
plt.show()  
1

There are 1 answers

8
MAHESH ARAVIND V On

You are trying to convert data in the title column to float right? You cant do that since there is some text in that column... You can convert a string containing a float say s = '1.234' to a float but you cant convert a string with text in it into a float.