Package: a-pandas-ex-old-school-for-loop
Tired of vectorization, df.apply and df.map? How about an old school inplace-for-loop? :)Usage - DataFramepipinstallfroma_pandas_ex_old_school_for_loopimportpd_add_old_school_for_looppd_add_old_school_for_loop()importpandasaspddf=pd.read_csv("https://raw.githubusercontent.com/pandas-dev/pandas/main/doc/data/titanic.csv")dfOut[3]:PassengerIdSurvivedPclass...FareCabinEmbarked0103...7.2500NaNS1211...71.2833C85C2313...7.9250NaNS3411...53.1000C123S4503...8.0500NaNS.......................88688702...13.0000NaNS88788811...30.0000B42S88888903...23.4500NaNS88989011...30.0000C148C89089103...7.7500NaNQ[891rowsx12columns]foritemindf.ds_set_values_with_loop():try:ifitem['get_value']()>2:item['set_value'](10000000)exceptException:continuedfOut[5]:PassengerIdSurvivedPclass...FareCabinEmbarked01010000000...10000000.0NaNS1211...10000000.0C85C210000000110000000...10000000.0NaNS31000000011...10000000.0C123S410000000010000000...10000000.0NaNS.......................8861000000002...10000000.0NaNS8871000000011...10000000.0B42S88810000000010000000...10000000.0NaNS8891000000011...10000000.0C148C89010000000010000000...10000000.0NaNQ[891rowsx12columns]Usage - Series in a DataFramefroma_pandas_ex_old_school_for_loopimportpd_add_old_school_for_looppd_add_old_school_for_loop()importpandasaspddf=pd.read_csv("https://raw.githubusercontent.com/pandas-dev/pandas/main/doc/data/titanic.csv")dfOut[3]:PassengerIdSurvivedPclass...FareCabinEmbarked0103...7.2500NaNS1211...71.2833C85C2313...7.9250NaNS3411...53.1000C123S4503...8.0500NaNS.......................88688702...13.0000NaNS88788811...30.0000B42S88888903...23.4500NaNS88989011...30.0000C148C89089103...7.7500NaNQ[891rowsx12columns]foritemindf.PassengerId.ds_set_values_with_loop():try:ifitem['get_value']()>2:item['set_value'](10000000)exceptException:continuedfOut[3]:PassengerIdSurvivedPclass...FareCabinEmbarked0103...7.2500NaNS1211...71.2833C85C21000000013...7.9250NaNS31000000011...53.1000C123S41000000003...8.0500NaNS.......................8861000000002...13.0000NaNS8871000000011...30.0000B42S8881000000003...23.4500NaNS8891000000011...30.0000C148C8901000000003...7.7500NaNQ[891rowsx12columns]Update lists and dicts inside cellsfroma_pandas_ex_old_school_for_loopimportpd_add_old_school_for_loopfromrandomimportrandrangepd_add_old_school_for_loop()importpandasaspddf=pd.read_csv("https://raw.githubusercontent.com/pandas-dev/pandas/main/doc/data/titanic.csv")getrandomlist=lambdax:[[[randrange(1,100),randrange(1,100)]*1]*randrange(1,10)]df["listtest"]=df.PassengerId.map(getrandomlist)dfOut[4]:PassengerId...listtest01...[[[88,15],[88,15],[88,15],[88,15]]]12...[[[15,63],[15,63],[15,63],[15,63],[15,...23...[[[46,9],[46,9],[46,9],[46,9]]]34...[[[71,12],[71,12],[71,12],[71,12]]]45...[[[55,44],[55,44],[55,44],[55,44],[55,..............886887...[[[81,15],[81,15],[81,15],[81,15],[81,...887888...[[[18,70]]]888889...[[[16,35]]]889890...[[[48,54],[48,54],[48,54],[48,54],[48,...890891...[[[11,99],[11,99],[11,99],[11,99],[11,...foritemindf.listtest.ds_set_values_with_loop():try:ifitem['get_value']()>15:item['set_value'](15000000)exceptException:continuedfOut[6]:PassengerId...listtest01...[[[15000000,15],[15000000,15],[15000000,1...12...[[[15,15000000],[15,15000000],[15,1500000...23...[[[15000000,9],[15000000,9],[15000000,9],...34...[[[15000000,12],[15000000,12],[15000000,1...45...[[[15000000,15000000],[15000000,15000000],..............886887...[[[15000000,15],[15000000,15],[15000000,1...887888...[[[15000000,15000000]]]888889...[[[15000000,15000000]]]889890...[[[15000000,15000000],[15000000,15000000],...890891...[[[11,15000000],[11,15000000],[11,1500000...[891rowsx13columns]