How to update column IsLCap column in dataframe based on Lvalue column whether it is capitilized or not.

df.loc[df.Lvalue.istitle(), 'IsLCap'] = 1 # need to be corrected

getting an error -AttributeError: 'Series' object has no attribute 'istitle'


You access string functions with .str. This should work:

df.loc[df.Lvalue.str.istitle(), 'IsLCap'] = 1

Update To check the length of the strings in the column you can use the string method .str.len:

df.loc[df.Lvalue.str.len() < 3, 'less_than_three'] = 1

Pandas Series string methods

  • $\begingroup$ i need to check string length also, df.loc[len(df.Lvalue)<3, 'LlessThan3'] = 1 ## need to correct this. How can i do this $\endgroup$ Jan 28 '19 at 21:16
  • $\begingroup$ I have updated my answer with a solution. If this works for you, you should accept/upvote the answer. @SUHASINIKL $\endgroup$
    – mbass
    Jan 28 '19 at 21:30

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.