简体   繁体   中英

Convert 2 columns of a dataframe storing two uint8_t in a column of the corrisponding uint16_t

Hi I am using Python and I want to convert 2 columns of a dataframe as:

data[col1]:{1,2,3} [0b00000001,0b00000010,0b00000011]
data[col2]:{1,2,3} [0b00000001,0b00000010,0b00000011]

in a column of the binary aggregation of the two, as:

data[col3]:{257,514,771} [0b0000000100000001,0b0000001000000010,0b0000001100000011]

Have you any ideas?

Thanks!

I have never tried to do bit shifting on pandas columns or numpy arrays, but simple operations are enough here:

data['col3'] = (data['col1'] * 256) + data['col2']

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM