How can I use function with pandas dataframe. For example:
a | b
london | uk
newyork | usa
berlin | germany
df1 = df[['a', 'b']]
def doSomething(df1):
return df1
doSomething() will return both columns a and b, But how do I return say only a?
def doSomething(df1):
return df1.a
df1.applymap(doSomething)
AttributeError: ("'str' object has no attribute 'a'", u'occurred at index a')
df1['a']does not work ?applymapcalls the function on every element of the dataframeTypeError: ('string indices must be integers, not str', u'occurred at index a')