I have the following dataframe:
+-------------------------------------------+----------------------------------------+----------------+----------------------------------+
| Lookup | LookUp Value 1 | LookUp Value 2 | LookUp Value 3 |
+-------------------------------------------+----------------------------------------+----------------+----------------------------------+
| 300000,50000,500000,100000,1000000,200000 | -1820,-1820,-1820,-1820,-1820,-1820 | 1,1,1,1,1,1 | 1820,1820,1820,1820,1820,1820 |
| 100000,1000000,200000,300000,50000,500000 | -1360,-28760,-1360,-28760,-1360,-28760 | 2,3,2,3,2,3 | 4120,31520,4120,31520,4120,31520 |
+-------------------------------------------+----------------------------------------+----------------+----------------------------------+
Each column is a list, the first columns is the lookup key and the rest are the lookup value. I would like to generate the dataframe like this.
+--------------------+--------------------+--------------------+
| Lookup_300K_Value1 | Lookup_300K_Value2 | Lookup_300K_Value3 |
+--------------------+--------------------+--------------------+
| -1820 | 1 | 1820 |
| -28760 | 3 | 31520 |
+--------------------+--------------------+--------------------+
Actually I have a solution using pandas.apply and process row by row. It is very very slow so I would like to see if there are some solution that could speed up the process? Thank you very much.
EDIT: I added the dataframe generation code below
d = {'Lookup_Key': ['300000,50000,500000,100000,1000000,200000', '100000,1000000,200000,300000,50000,500000'],
'LookUp_Value_1': ['-1820,-1820,-1820,-1820,-1820,-1820', '-1360,-28760,-1360,-28760,-1360,-28760'],
'LookUp_Value_2': ['1,1,1,1,1,1', '2,3,2,3,2,3'],
'LookUp_Value_3': ['1820,1820,1820,1820,1820,1820', '4120,31520,4120,31520,4120,31520']}
df = pd.DataFrame(data=d)
See Question&Answers more detail:
os