Pandas loc and trying what you learned

Watched YouTube video that showed the loc method to locate a value in your data.

df.loc[df["column"]=="string"])

However when I tried it on a first name field that I knew was there ...it didn't find any. My data had trailing spaces and I found that if I added trailing spaces to the string ("string ") it found the name.

But that's not a good way to handle the problem. I knew I had to get rid of the trailing spaces. Solution...use the strip() function. I could have used rstrip , for trailing spaces but strip removes leading and trailing spaces. Perhaps rstrip would be slightly faster?

df.loc[df["First"].str.strip()=="string"]

This is because I originally formatted the data fixed length with no delimiter to be copied to a mainframe. Which also takes up a lot more space. I really need to reformat it delimited only with no padding!

This is how you learn. By trying what you learned. And when it doesn't work...you'll learn even more figuring out why!

2020-07-03 23:08:51
Index