I'm trying to write a script (see below code) to check if any of the values in the 'Mobile Phone Number' column exceeds the length of 11. If there is, then print the index of this value and delete the entire record of this index from the data frame. However, the program is not doing this line of code correctly: if len(data['Mobile Phone Number']) > 11:
even though the condition is met? There are two phone numbers exceeding the length of 11
that I need to delete.
import pandas as pd
data = {
'Name': [
'Tom',
'Joseph',
'Krish',
'John'
],
'Mobile Phone Number': [
13805647925,
145792860326480,
184629730518469,
18218706491
]
}
df = pd.DataFrame(data)
print(df)
for i in range(len(data)):
if len(data['Mobile Phone Number']) > 11:
print('Number at index ', i, 'is incorrect')
data = data.drop(['Mobile Phone Number'][i], axis=1)
else:
print('\nNo length of > 11 found in Mobile Phone Numbers')
And this is the output of the above code:
Name Mobile Phone Number
0 Tom 13805647925
1 Joseph 145792860326480
2 Krish 184629730518469
3 John 18218706491
No length of > 11 found in Mobile Phone Numbers
No length of > 11 found in Mobile Phone Numbers