0

below startswith query runs fine in my PyCharm environment (Python 2.7):

df['starts_with'] = map(lambda x: df.startswith('Wash'), df['CTYNAME'])

When running the same in a Jupyter Notebook I am receiving below value in my 'starts_with' column:

'<map object at 0x7fbfe6954470>' 

I understand that it might be a purely Jupyter issue, however, is there a different approach to this query to get around the error in Jupyter? 'starts_with' shall be used for a boolean mask in a next step.

Best, P

Peter
  • 553
  • 3
  • 7
  • 15
  • 1
    What are you doing with the value? Printing it? In any case what you see is a string representation of the object. Different environments might represent objects differently. Read more about that [here: Difference between __str__ and __repr__ in Python](https://stackoverflow.com/questions/1436703/difference-between-str-and-repr-in-python) – Adelin Jan 11 '18 at 10:15
  • That does not look like Python 2.7 – ayhan Jan 11 '18 at 10:16
  • Adelin: 'starts_with' shall be used for a boolean mask in a next step. – Peter Jan 11 '18 at 10:23

2 Answers2

0

It's probably not an error. The map you're accessing is not the python's builtin map, but rather some implementation which instead of ready result returns an object which implements everything you'd expect from an iterable list, but does some optimisation magic underneath.

If you want it to be a list, you can try:

list(map(....))

Otherwise, you could try iterating it and see if you get a result you expect.

viraptor
  • 33,322
  • 10
  • 107
  • 191
0

Sorry for troubling you, figured it out myself while editing my initial inquiry: I just concatenated the query with my previous line for boolean masking.

print(map(lambda x: df.startswith('Wash'), df['CTYNAME'])[PREVIOUS_DF])
Peter
  • 553
  • 3
  • 7
  • 15