0

So I have a dataframe like this

   customer     location       trip_len
0     a      ['1', '2', '3']      3
1     b      ['4', '5']           2

And I am trying to hash, for every row, every element on the list of strings on the column 'location' in order to improve efficiency in my model. How would this be possible?

2
  • 2
    What do you mean by "hash" in this context? It'd help if you could edit to describe what you actually want to achieve please. eg: after this "hash"ing... what would your DF look like or what would you want to be doing with it? Providing more context here would be fabulous - thanks. Commented Sep 28, 2019 at 16:35
  • Do you want to categorize your values? Perhaps something like sklearn's ordinal encoder? Commented Sep 29, 2019 at 2:16

1 Answer 1

1

Lists are not natively hashable as those are mutable objects. If only storage is of interest converting to a tuple is an option.

df.location = df.location.apply(lambda locations: hash(tuple(locations)))
Sign up to request clarification or add additional context in comments.

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.