Reputation: 16375
print(df["date"].str.replace("2016","16"))
The code above works fine. What I really want to do is to make this replacement in just a small part of the data-frame. Something like:
df.loc[2:4,["date"]].str.replace("2016","16")
However here I get an error:
AttributeError: 'DataFrame' object has no attribute 'str'
Upvotes: 0
Views: 48
Reputation: 5741
What about df['date'].loc[2:4].str.replace('2016', 16')
?
By selecting ['date']
first you know you are dealing with a series which does have a string attribute.
Upvotes: 2