1

This code :

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)

Gives me this error:

AttributeError: 'Series' object has no attribute 'columns' `

I have tried different things with pd.DataFrame and pd.Series, without luck. What do i wrong?

Result of pd.read_csv: enter image description here

Expected output: enter image description here

Error code:

enter image description here

9
  • if data is a pd.Series, it indeed has no columns. Can you check its type - what is the result of the pd.read_csv? Commented Oct 28, 2019 at 11:23
  • 1
    Do you need data.hist(column ='msg_length', by='label', bins=50) ? Commented Oct 28, 2019 at 11:24
  • does not work @jezrael Commented Oct 28, 2019 at 11:35
  • @ItamarMushkin i have added a picture to the question Commented Oct 28, 2019 at 11:39
  • What is expected output ? Commented Oct 28, 2019 at 11:39

2 Answers 2

1

Use DataFrame.hist with columns in strings instead Series like data['msg_length']:

data.hist(column ='msg_length', by='label', bins=50)
Sign up to request clarification or add additional context in comments.

Comments

0
data.hist(column ='msg_length', by='label')  

did the job

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.