Skip to content

Tag: dataframe

How to export pandas dataframe with Multi-index columns to Excel with column name in one level unmerged and column name in another level merged?

I have a pandas dataframe df which looks as follows: The columns are Multi-Index consisting of 3 levels. First level has Germany as country. Second level has some indicators, and third level has years. And there are some data in the pandas dataframe. I’d like to export this dataframe to Excel such that …

How do I do a groupby in python to split between orders?

I have a dataframe that shows order listing. How do I use it to find the number of orders that contain spicy food? Using this code gives me 2 Yes and 2 No, but it should actually be 2 Yes and 1 No as order 1001 is duplicated. Thank you. I would like to get an output that shows the

Sort a dict of DataFrames

I have a dict of data-frames like the following: symbols ={BTC: DF, ETH: DF, DOGE:df} where each DF looks like this. I am trying to sort the dict by the price_change in the last row. Answer You could figure out the sorting of the keys by using a lambda function on sorted, which gets the last price change per …