我有以下数据框,
ip_df:
ble gw_mac Uuid rawData
ac233f264920 ac233fc01403 e2c56db5dffb48d2b060d0f5a71096e0 0
ac233f264920 ac233fc015f6 e2c56db5dffb48d2b060d0f5a71096e0 0
ac233f264920 ac233fc02eaa e2c56db5dffb48d2b060d0f5a71096e0 0201060303aafe1116aafe20000bdf160006c39e0b1484bee4
ac233f26492b ac233fc01403 e2c56db5dffb48d2b060d0f5a71096e0 0201060303aafe1116aafe20000bf115000618d2ef1484c2fe
ac233f26492b ac233fc015f6 e2c56db5dffb48d2b060d0f5a71096e0 0
ac233f26492b ac233fc02eaa 0 0201060303aafe1116aafe20000bdf160006c39e0b1484bee4
我需要根据以下条件对新列进行分组和框架
我的结果应该是
ip_df:
ble gw_mac type payload
ac233f264920 ac233fc01403 iBeacon e2c56db5dffb48d2b060d0f5a71096e0
ac233f264920 ac233fc015f6 iBeacon e2c56db5dffb48d2b060d0f5a71096e0
ac233f264920 ac233fc02eaa iBeacon e2c56db5dffb48d2b060d0f5a71096e0
ac233f26492b ac233fc01403 iBeacon e2c56db5dffb48d2b060d0f5a71096e0
ac233f26492b ac233fc015f6 iBeacon e2c56db5dffb48d2b060d0f5a71096e0
ac233f26492b ac233fc02eaa other 0201060303aafe1116aafe20000bdf160006c39e0b1484bee4
现在我正在迭代数据帧以检查上述条件,
for index, row in ip_df.iterrows():
if row['Uuid'] != 0 and row['rawData'] == 0:
ip_df.loc[index, 'payload'] = row['Uuid']
ip_df.loc[index, 'type'] = str("iBeacon")
elif row['Uuid'] != 0 and row['rawData'] != 0:
ip_df.loc[index, 'payload'] = row['Uuid']
ip_df.loc[index, 'type'] = str("iBeacon")
elif row['Uuid'] == 0 and row['rawData'] != 0:
ip_df.loc[index, 'payload'] = row['rawData']
ip_df.loc[index, 'type'] = str("other")
如何用大熊猫数据框的groupby实现相同的逻辑?