Reputation: 5283
I am simply applying some filter on data-frame and calculation 1st Quartile, but it shows me error like "TypeError: argument of type 'float' is not iterable". many sources says that it is because of NAN value in your data frame but i can not ignor that row.
# Import pandas
import pandas as pd
import numpy as np
outstanding_df = pd.read_csv("outstandings-Pune-PCMC-Nov2019_.csv")
outstanding_df.head()
Outstandings YearMonthNum StoreId StoreName storepartycode storepartyname storepartypincode storepartyaddress1 storepartyaddress2 RegionId RegionName InvoiceAmount ReceivedAmount OutstandingBalance
0 Outstandings 201911 1475 TAPADIYA COSMOGEN 6452 MIRA MEDICAL 0.0 BIBVEWADI PUNE UNITY HEIGHTS 1 Pune 168.0 0.0 168.0
1 Outstandings 201911 1475 TAPADIYA COSMOGEN 9594 MEDICO POINT 411037.0 GANESH CORNERBIBVEWADI NaN 1 Pune 965.0 0.0 965.0
2 Outstandings 201911 1475 TAPADIYA COSMOGEN 6819 BALAJI MEDICAL NaN UNDRIHADAPSAR SHOP NO 4 MAHALAXMI MARKET 1 Pune 3204.0 0.0 3204.0
3 Outstandings 201911 1475 TAPADIYA COSMOGEN 2137 PERFECT MEDICAL GEN STORES NaN KONDHAWA. NIBM ROAD. SHOP NO 4 SUNSHREE D2 1 Pune 1719.0 0.0 1719.0
4 Outstandings 201911 1475 TAPADIYA COSMOGEN 8601 SAI MEDICAL GENERAL STORE NaN NIBM ROAD SUNSHREE SUNTEC SHOP NO 20 1 Pune 725.0 0.0 725.0
_
outstanding_df['Flag'] = ""
Distributors = ['agency','dist','distributor','pharma','agencies']
for index, row in outstanding_df.iterrows():
if any(word in row['storepartyname'] for word in Distributors):
#print(row['storepartyname'])
outstanding_df.at[index,'Flag']='True'
# find the quantiles over the index axis
outstanding_df['InvoiceAmount'].quantile(.25) # 4th Quartile data Value
# Apply Filter for OrderAmount!=True
a = outstanding_df[outstanding_df['InvoiceAmount']!='True']
print(a['InvoiceAmount'].quantile(.25)) # 4th Quartile data Value
_
---------------------------------------------------------------------------
TypeError Traceback (most recent call last)
<ipython-input-100-af5f80284d23> in <module>
5 Distributors = ['agency','dist','distributor','pharma','agencies']
6 for index, row in outstanding_df.iterrows():
----> 7 if any(word in row['storepartyname'] for word in Distributors):
8 #print(row['storepartyname'])
9 outstanding_df.at[index,'Flag']='True'
<ipython-input-100-af5f80284d23> in <genexpr>(.0)
5 Distributors = ['agency','dist','distributor','pharma','agencies']
6 for index, row in outstanding_df.iterrows():
----> 7 if any(word in row['storepartyname'] for word in Distributors):
8 #print(row['storepartyname'])
9 outstanding_df.at[index,'Flag']='True'
TypeError: argument of type 'float' is not iterable
Sample CSV Data
Outstandings,YearMonthNum,StoreId,StoreName,storepartycode,storepartyname,storepartypincode,storepartyaddress1,storepartyaddress2,RegionId,RegionName,InvoiceAmount,ReceivedAmount,OutstandingBalance
"Outstandings",201911,1475,"TAPADIYA COSMOGEN","6452","MIRA MEDICAL","0","BIBVEWADI PUNE","UNITY HEIGHTS",1,"Pune",168.00,0.00,168.00
"Outstandings",201911,1475,"TAPADIYA COSMOGEN","9594","MEDICO POINT","411037","GANESH CORNERBIBVEWADI","N/A",1,"Pune",965.00,0.00,965.00
"Outstandings",201911,1475,"TAPADIYA COSMOGEN","6819","BALAJI MEDICAL","N/A","UNDRIHADAPSAR","SHOP NO 4 MAHALAXMI MARKET",1,"Pune",3204.00,0.00,3204.00
"Outstandings",201911,1475,"TAPADIYA COSMOGEN","2137","PERFECT MEDICAL GEN STORES","N/A","KONDHAWA. NIBM ROAD.","SHOP NO 4 SUNSHREE D2",1,"Pune",1719.00,0.00,1719.00
"Outstandings",201911,1475,"TAPADIYA COSMOGEN","8601","SAI MEDICAL GENERAL STORE","N/A","NIBM ROAD","SUNSHREE SUNTEC SHOP NO 20",1,"Pune",725.00,0.00,725.00
"Outstandings",201911,1475,"TAPADIYA COSMOGEN","1820","METRO CHEMIST.","0","KONDHAWA. 26830382","SHOP NO 4NOVEDITA GARDEN",1,"Pune",896.00,0.00,896.00
"Outstandings",201911,1475,"TAPADIYA COSMOGEN","298","VISHWAS MEDICO","N/A","ERANDWANA PH.5448865","SIDDHARTH APTS.PUNE",1,"Pune",272.00,0.00,272.00
"Outstandings",201911,1475,"TAPADIYA COSMOGEN","567","MUKESH MEDICALS","0","PAUD ROAD RAMBHAG COL KOTHRUD","RAJDEEP APPT",1,"Pune",201.00,0.00,201.00
"Outstandings",201911,1475,"TAPADIYA COSMOGEN","8569","GAURAV MEDICAL","N/A","SUDARSHAN APPT. KOTHRUD","SHOP NO 8 SHILAVIHAR COLONY",1,"Pune",979.00,0.00,979.00
"Outstandings",201911,1475,"TAPADIYA COSMOGEN","10383","SAMRUDHI MEDICAL SUPER STORE","0","SNEH PARADISE MIT COLLEGE RD","KOTHRUD",1,"Pune",806.00,0.00,806.00
"Outstandings",201911,1475,"TAPADIYA COSMOGEN","9715","PAVAN CHEMIST","0","SHOP NO-5MANGAL CLASSIC HISSA","OPP SURYAPRABHA PAUD ROAD",1,"Pune",477.00,0.00,477.00
"Outstandings",201911,1475,"TAPADIYA COSMOGEN","5417","LAXMI MEDICAL","N/A","KOTHRUD SHIVTHIRTHNAGAR","N/A",1,"Pune",1457.00,0.00,1457.00
"Outstandings",201911,1475,"TAPADIYA COSMOGEN","404","SOURABH MEDICALS GEN STORES","0","POUD ROAD","PRANJAL COPTV HSG SOC",1,"Pune",2245.00,0.00,2245.00
"Outstandings",201911,1475,"TAPADIYA COSMOGEN","3604","ROYAL MEDICO","0","PAUD ROAD","RAHUL COMPLEX SHOP NO 23",1,"Pune",1464.00,0.00,1464.00
"Outstandings",201911,551,"Meena Pharma","4221","CENTRAL MEDICAL STORES","0","GRANT MEDICAL FOUNDATION","RUBY HALL CLINIC SASOON ROAD",1,"Pune",21157.00,0.00,21157.00
"Outstandings",201911,1475,"TAPADIYA COSMOGEN","10070","AAIJI MEDICO","0","KUMAR PRANGANSHOP NO 3","NEAR WARJE KSHETRIYA KARYALAY",1,"Pune",2991.00,0.00,2991.00
"Outstandings",201911,1475,"TAPADIYA COSMOGEN","319","JEEVAN MEDICALS","N/A","KARVENAGARMADHUBAN COLONY","SHOP NOP 3 38/2",1,"Pune",758.00,0.00,758.00
"Outstandings",201911,1475,"TAPADIYA COSMOGEN","822","GETWELL MEDICAL","0","ERANDWANE.PH.NO.25451628","PUNE.",1,"Pune",813.00,0.00,813.00
"Outstandings",201911,1475,"TAPADIYA COSMOGEN","4792","MEDICO HOUSE.","0","KOTHRUD 9823250106","SHOP NO 2/3 VARUN COMPLEX",1,"Pune",652.00,0.00,652.00
"Outstandings",201911,15,"New Amar Agencies","4000","SHRI MEDICAL (ST)##","N/A","GHODNADI SHIRUR DR.UPLENCHWAR","GHODNADI SHIRUR DR.UPLENCHWAR",1,"Pune",22547.00,0.00,22547.00
"Outstandings",201911,7,"Anand Medical Distributors","5178","SONY MEDICALS","N/A","KONDHWA","N/A",1,"Pune",552.00,0.00,552.00
"Outstandings",201911,31,"Shah Enterprises","4768","MAULI MEDICAL & GEN STORES","N/A","SIHGAD ROAD","PUNE,",1,"Pune",169.00,0.00,169.00
"Outstandings",201911,31,"Shah Enterprises","7668","SHREE VINAYAK MEDICAL CENTRE","N/A","GHORPADE PETH","PUNE,",1,"Pune",545.00,0.00,545.00
"Outstandings",201911,31,"Shah Enterprises","9791","SHREE KOHINOOR MEDICO ( DHAYARI )","N/A","SHOP NO.2 & 3 NEAR UMBARYA GANPATI","UMBARYA GANPATI MITRA MANDAL",1,"Pune",84.00,0.00,84.00
"Outstandings",201911,33,"Premier Distributors","3642","OM MEDICO & GENERAL ST.","N/A","SHOP NO1 OPP SANSKRUTI APTS HANDEWADI ROAD UDYOG NAGAR","HADAPSAR",1,"Pune",114.00,0.00,114.00
"Outstandings",201911,33,"Premier Distributors","7060","KRISHNA MEDICAL & GEN STORES","N/A","SHOP.NO.2, PAARGE CHOWK,","KONDHWA KHURD",1,"Pune",132.00,0.00,132.00
"Outstandings",201911,33,"Premier Distributors","2871","LAXMI MEDICAL & GEN STORES","N/A","NEAR KAWDE HOSPITAL N.D.A. SHIVANE UTTAMNAGAR PUNE -23","N/A",1,"Pune",167.00,0.00,167.00
"Outstandings",201911,33,"Premier Distributors","10462","SHRI SADGURU KRUPA MEDICAL","N/A","SHOP NO.8 SR.NO.114/115/16","RAGHUNANDAN PLAZA PUNE BANGLORE HIGHWAY",1,"Pune",83.00,0.00,83.00
Upvotes: 2
Views: 3749
Reputation: 5283
I resolved the error by just converting row['storepartyname'] into string dynamically like str(row['storepartyname'])
Final working code
outstanding_df['Flag'] = ""
Distributors = ['agency','dist','distributor','pharma','agencies']
for index, row in outstanding_df.iterrows():
if any(word in str(row['storepartyname']) for word in Distributors):
#print(row['storepartyname'])
outstanding_df.at[index,'Flag']='True'
# find the quantiles over the index axis
outstanding_df['InvoiceAmount'].quantile(.25) # 4th Quartile data Value
# Apply Filter for OrderAmount!=True
a = outstanding_df[outstanding_df['InvoiceAmount']!='True']
print(a['InvoiceAmount'].quantile(.25)) # 4th Quartile data Value
Upvotes: 1