Planet_Z Planet_Z -4 years ago 162
Python Question

retrieve all values in column exceeding 5 strings - pandas dataframe

I have a column in dataframe - df where all values should be length of 5 strings/characters but due to an error in my code, some have erroneous values and length of strings is either below 5 or greater than 5. Is there a way to just retrieve these columns?

Answer Source

How does this work for you? This will return a dataframe where values meet the condition.

new_DF= your_df[your_df['COLUMN TO CHECK HERE'].str.len() != 5]
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download