1

I am calculating the frequency of each sequence in df:

VD_1    VD_2    VD_2
35000   35090   31550
35000   35090   31550
35099   45097   
35099   45097   
35099   45097

If I do run the code given below, I get an error TypeError: ('sequence item 0: expected string, numpy.int64 found', u'occurred at index 1'). In fact, the code works fine on the other dataset, but here it fails:

df['data'] = df.apply(lambda x: '/'.join(x.dropna()), axis=1)
df = df.data.value_counts().rename_axis('count').reset_index()
df

The result should be this one:

data                count
35000/35090/31550   2
35099/45097         1

1 Answer 1

2

It seems you need add astype(str) for cast int to string:

df['data'] = df.apply(lambda x: '/'.join(x.dropna().astype(str)), axis=1)
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.