此代码:
import pandas as pd
data = pd.read_csv('house', sep="\t", header=None)
data.columns = ['label', 'msg']
data['msg_length'] = data['msg'].apply(lambda x: len(x))
data['msg'].hist(column =data['msg_length'], by=data['label'], bins=50)
给我这个错误:
AttributeError:“系列”对象没有属性“列”
我用pd.DataFrame和pd.Series尝试了不同的方法,但是没有运气。 我怎么了?
错误代码:
答案 0 :(得分:1)
将DataFrame.hist
与字符串列一起使用,而不是Series
,例如data['msg_length']
:
data.hist(column ='msg_length', by='label', bins=50)
答案 1 :(得分:0)
data.hist(column ='msg_length', by='label')
完成工作