简体   繁体   中英

Calcul len for each row in column and take only one who respect the condition Pandas Python

num_excel_file_3 ( here I have My matrice (Dataframe) index,row,column)

with Dataframe I Have:

在此处输入图像描述

Now I want to update all Dataframe with condition:

if len for each row in 'CLIENT NUM' < 6 I will keep this line

in this column I have string and number so what I do:

num_excel_file_3['CLIENT NUM'] = num_excel_file_3['CLIENT NUM'].astype(str)

Now I have string for each row ->:)

next step find the way len(num_excel_file_3['CLIENT NUM'].values < 6

for example:

dfini = num_excel_file_3[num_excel_file_3['CLIENT NUM'] !='10790'] work I delet the line where I have string(10790)

But what about len(......) <6 ?

Thank you guys

I find the way.!! I try during 3 hours but want to find easy way so I post here. After posted I find the answer !!

dfini=num_excel_file_3[num_excel_file_3['CLIENT NUM'].map(len) < 6]

print(dfini)

在此处输入图像描述

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM