0

I have a dataframe column which looks like:

df['Hits'] :
          High
          Medium
          Low
          Medium
          High

I want to convert it's string values to int values such that the column would look like:

df['Hits']:
           100
           50
           10
           50
           100

My code:

def convert_cache_range(i):
         density = {"High":100,
                    "Medium":50,
                    "Low":10}

data_frame.CacheRange = [convert_cache_range(i) for i in data_frame.CacheRange]

It returns NA as output in all rows

TjS
  • 277
  • 2
  • 5
  • 16
  • 1
    Just use [`map`](https://pandas.pydata.org/pandas-docs/stable/generated/pandas.Series.map.html): "If arg is a dictionary, return a new Series with values converted according to the dictionary’s mapping" – roganjosh Nov 15 '18 at 16:27
  • If you run `[convert_cache_range(i) for i in data_frame.CacheRange]` without assignment you'll notice that it returns a list of `None`s. That's because `convert_cache_range()` doesn't explicitly return a value. – Steven Rumbalski Nov 15 '18 at 16:28

0 Answers0