问题描述
我正在使用 python 对一些 csv 数据进行数据分割。我有以下列,如 Actionid、名称、标题。 给定列中的数据就像;
目前我遇到以下错误
我的代码是;
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()
解决方法
您正在尝试将标题列中的数据转换为浮动对吗? 您不能这样做,因为该列中有一些文本...您可以将包含浮点数的字符串如 s = '1.234' 转换为浮点数,但不能将包含文本的字符串转换为浮点数。