Create Multi-Index empty DataFrame to join with main DataFrame

Suppose that I have a dataframe which can be created using code below df = pd.DataFrame(data = {‘date’:[‘2021-01-01’, ‘2021-01-02’, ‘2021-01-05′,’2021-01-02’, ‘2021-01-03’, ‘2021-01-05’], ‘product’:[‘A’, ‘A’, ‘A’, ‘B’, ‘B’, ‘B’], ‘price’:[10, 20, 30, 40, 50, 60] } ) df[‘date’] = pd.to_datetime(df[‘date’]) I want to create an empty dataframe let’s say main_df which will contain all dates between… Read More Create Multi-Index empty DataFrame to join with main DataFrame

How to add another subcolumn to dataframe with multi-index

I’m trying to add a third column "Productivity" so every role like Admin would have three sub columns produktiv, unproduktiv and Productivity. Productivity would be calculated as follows: Productivity = Produktiv / (Produktiv + Unproduktiv) * 100 (don’t mind the s, I had to anonymize the data) Here is the output of df.columns Any help… Read More How to add another subcolumn to dataframe with multi-index

How to access index value(s), preferably by name, in MultiIndex DataFrame?

Let’s say we have a MultiIndex DataFrame, and said DataFrame looks something like this: 0 source date row Alpha 01-01 0 0.183436 1 -0.210341 Beta 02-01 0 -0.950784 1 0.259809 How would I go about getting the unique dates as a list in the shown order above? i.e. [’01-01′, ’02-01′] I know I can access… Read More How to access index value(s), preferably by name, in MultiIndex DataFrame?

Remove the column used for index with pd.MultiIndex.from_product

I have a dataframe like so dfDictionary = {‘Results’:[‘Home’, ‘Away’, ‘For’, ‘Against’ ], ‘info’:[ ‘-‘, ‘-‘,’-‘,’-‘,], ‘rating’:[ ‘-‘, ‘-‘,’-‘,’-‘,], ‘review’:[ ‘-‘, ‘-‘,’-‘,’-‘,]} dfTable1 = pd.DataFrame(dfDictionary) It looks like below Results info rating review 0 Home – – – 1 Away – – – 2 For – – – 3 Against – – – I created… Read More Remove the column used for index with pd.MultiIndex.from_product