468,291 Members | 1,742 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 468,291 developers. It's quick & easy.

Nested loop based number of filtered rows

My Csv File looks like below
Territory NoOfCustomer
D00060 10
D00061 20
D00065 70
D00067 90

I have to create a Unique Id based on Number of NoOfCustomer like If NoOfCustomer <=50
then I have to create 10 different Unique ID for Territory D00060 and 10 different Unique ID for Territory D00061.

Here I read my csv file in pandas like

csv_file = 'cust_valid.csv'
df=pd.read_csv(csv_file,delimiter="|")

Filtered having customers <= 50

low_dense = df['NoOfCustomer'] <=50

And then iterted low_dense like
This part will only iterate the filterd zip_codes

for index,row in Highly_low.iterrows():
for loop in row:
print('S')

Here I wanna a write to another CSV file with columns like

Territory NoOfCustomers UniqueId
D00060 10 0001ASDDF900f
D00060 10 qwdfeed0909jkl
D00060 10 lhjkhj90090kllkm
D00060 10 jhjkhjk0909090
Oct 18 '18 #1
0 1013

Post your reply

Sign in to post your reply or Sign up for a free account.

Similar topics

25 posts views Thread by chad | last post: by
5 posts views Thread by Blankdraw | last post: by
4 posts views Thread by Ed | last post: by
8 posts views Thread by TobbeK | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.