I have the following Python data frame:
state_data = {'State':['Alabama','Alaska','Arizona','Arkansas'],'PostCode':['AL','AK','AZ','AR'],'Area':['52,423','656,424','*','53,182'],'Pop':['4,040,587','550,043','3,665,228','2,350,750']}
state_data
import pandas as pd
df = pd.DataFrame(state_data)
dfdiff = df.set_index('State')
dfdiff
myfunc = lambda x: x.replace(',','')
dfdiff = map(myfunc,(dfdiff['Area'],dfdiff['Pop'])
dfdiff
I am successfully able to make a 'nameless' function with lambda, but am running into issues when attempting to apply it using the map function.
The error reads as follows:
TypeError: 'map' object is not subscriptable
How can I apply these changes to my dfdiff
data frame through the map function (or is there a better way)?