asks_price asks_qty exchange_name_ask bids_price bids_qty exchange_name_bid
0 20156.51 0.000745 Coinbase 20153.28 0.000200 Coinbase
1 20157.52 0.050000 Coinbase 20152.27 0.051000 Coinbase
2 20158.52 0.000745 Coinbase 20151.28 0.000200 Kraken
3 20158.52 0.050000 FTX 20151.28 0.051000 Coinbase
I would like to group the same price, add quantity together and combine the name of the exchange like :
asks_price asks_qty exchange_name_ask bids_price bids_qty exchange_name_bid
0 20156.51 0.000745 Coinbase 20153.28 0.000200 Coinbase
1 20157.52 0.050000 Coinbase 20152.27 0.051000 Coinbase
2 20158.52 0.050745 CoinbaseFTX 20151.28 0.051200 KrakenCoinbase
I received a good answer simply if it is the same name I do not want it to be concat, example CoinbaseCoinbase. How can i do that ?
group
the dataframe byasks_price
then callsum
passingFalse
tonumeric_only
argument, the solution assumes that the data is in the order you've provided in the sample data, else you need to handle the logic for sorting:You can call
reset_index()
at last if you want to have prices as column rather than index.