I don't know why the index method has inconsistent behavior while doing column-wise apply function.
The data frame is:
df = pd.DataFrame( [(1, 'Hello'), (2, "World")])
df.columns=['A', 'B']
And I want to apply lambda to the second columns, it it saying the Series object can not be apply?
print df.iloc[:, 1:2].apply(lambda x: x.upper()).head()
**AttributeError**:("'Series' object has no attribute 'upper'", u'occurred at index B')
print df.loc[:, ['B']].apply(lambda x: x.upper()).head()
**AttributeError**:("'Series' object has no attribute 'upper'", u'occurred at index B')
But rather the following indexing method works well.
print df.loc[:, 'B'].apply(lambda x: x.upper()).head()
Why? I think the three index methods are equivalent? All above three indexing method has almostly the same result if print out that is:
B
0 Hello
1 World
and print df.loc[:, 'B'] gets
0 Hello
1 World
Name: B, dtype: object
What do the differences mean?