0

I have data in pandas dataframes in the form

|timestamp|bssid|dbm|other cols|
|---------|-----|---|----------|
|12345678 |mac 1|-50|text      |
|---------|-----|---|----------|
|87654321 |mac 2|-70|text 2    |
|---------|-----|---|----------|

I am trying to transform it into

|timestamp|mac 1|mac 2|
|---------|-----|-----|
|12345678 |-50  | NaN |
|---------|-----|-----|
|87654321 | NaN | -70 |
|---------|-----|-----|

I have so far tried to use df.pivot(index='timestamp', columns='bssid', values='dbm') but this results in

|bssid     |mac 1|mac 2|
|----------|-----|-----|
|timestamp |     |     |
|----------|-----|-----|
|12345678  | -50 | NaN |
|----------|-----|-----|
|87654321  | NaN | -70 |
|----------|-----|-----|

My question is if there is either a different way to generate the table I want, or how I can transform the table I now have into the table I want.

Additional info about my last table: df.columns yields Index(['mac 1', 'mac 2', ..., 'mac n'], dtype='object', name='bssid', length=163)

df.axes yields [Int64Index([12345678, 87654321], dtype='int64', name='timestamp'), Index(['mac 1', 'mac 2', ..., 'mac n'], dtype='object', name='bssid', length=163)]

c4edus
  • 25
  • 5
  • 1
    Do you need `timestamp` like column? How working `df.pivot(index='timestamp', columns='bssid', values='dbm').reset_index().rename_axis(None, axis=1)` ? – jezrael Mar 03 '20 at 07:07
  • @jezrael perfect! thank you a lot. It's really tough to ask questions when you don't know what exacty you're asking for – c4edus Mar 03 '20 at 07:11
  • yop, I understand you. – jezrael Mar 03 '20 at 07:12

0 Answers0