Dinosaurius
Dinosaurius

Reputation: 8628

TypeError: ('sequence item 0: expected string, numpy.int64 found', u'occurred at index 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

Upvotes: 1

Views: 1414

Answers (1)

jezrael
jezrael

Reputation: 863226

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)

Upvotes: 2

Related Questions