0

Dears, I have dataframe contain many columns and rows(40000 rows)as below,

enter image description here

Many rows have "CVLAN_description" column are NAN, I want to fill it by other row has value under some condition if two columns are equal('C-VLAN' and 'SPO Name' ), these means by traditional way i will have two inner for loops to iterate each row to all rows to see if the condition matches or not, that will led to 40000*40000 iterations , these may be take hours in my laptop when running my code:

for index, row in with_VLANe_after.iterrows():
        if row['CVLAN_description']!='nan':
            for index2, row2 in with_VLANe_after.iterrows():
               if  row['C-VLAN'] ==row2['C-VLAN'] and 
                  row2['Service_name']=='nan' and row['SPO Name'] 
                  ==row2['SPO Name'] and 
                  row['S-VLAN'] ==row2['S-VLAN']  : with_VLANe_after.set_value(index2,'CVLAN_description',row['CVLAN_description'])
                 print (row['CVLAN_description'])

Any one can help me to avoid long time iteration.

  • 1
    Please share a sample of `with_VLANe_after` – yatu Dec 10 '18 at 15:29
  • Hi, welcome to StackOverflow. Please see [How to ask](https://stackoverflow.com/help/how-to-ask) and [How to create a MCVE](https://stackoverflow.com/help/mcve). For `pandas`, see [How to ask a good pandas question](https://stackoverflow.com/questions/20109391/how-to-make-good-reproducible-pandas-examples). – Evan Dec 10 '18 at 18:37

0 Answers0