1

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()  
Amaze_Rock
  • 163
  • 3
  • 16

1 Answers1

0

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.

  • Thanks! but there should be some way to do it? It may come with any of the columns in different way. There is huge data in csv. – Amaze_Rock Jun 03 '21 at 06:38
  • You can convert if the data contains proper data that can be converted. There is no meaning to convert say "HELLO" into a decimal. If you have a valid string containing numeric value, we can use float() or int() functions to convert. @Amaze_Rock – MAHESH ARAVIND V Jun 03 '21 at 06:40
  • Is there anything for special character? – Amaze_Rock Jun 03 '21 at 06:41
  • What do you mean by a special character? – MAHESH ARAVIND V Jun 03 '21 at 06:42
  • if special characters comes with number and string. – Amaze_Rock Jun 03 '21 at 06:44
  • OK you have a string containing some characters and some numbers and you want to convert the numeric part alone to a float am I correct? In that case you can either go letter by letter yourself or use the filter method. DM me if you still dont get it : ) – MAHESH ARAVIND V Jun 03 '21 at 06:50
  • Let us [continue this discussion in chat](https://chat.stackoverflow.com/rooms/233263/discussion-between-mahesh-aravind-v-and-amaze-rock). – MAHESH ARAVIND V Jun 03 '21 at 06:51
  • Thanks... I will check your solution... I was busy in some other assignment and was not able to check your response yesterday. Will connect if I am with any queries.. Good Day... TC. – Amaze_Rock Jun 04 '21 at 05:10