Linked Questions

0 votes
2 answers
865 views

I have the following code: import pandas as pd arrays = [['Falcon', 'Falcon', 'Parrot', 'Parrot'], ['Captive', 'Wild', 'Captive', 'Wild']] index = pd.MultiIndex.from_arrays(arrays, names=('...
Andrey's user avatar
  • 6,639
0 votes
0 answers
240 views

I have the following reproducible code in which I create a dictionary, I group it by the factor Metropolitan Area and I use the agg() function to determine the mean by factor: dictionaryMLB = {'...
Mauro's user avatar
  • 479
2 votes
1 answer
67 views

How do I convert a MultiIndex DataFrame to a Standard index DF? import pandas as pd df1 = pd.DataFrame({'old_code': ['00000001', '00000002', '00000003', '00000004'], 'Desc': ['99999991', '99999992 or ...
Lee Murray's user avatar
1 vote
1 answer
58 views

I have a dataframe that has a redundant set of columns that I would like to get rid of. My actual use case is a bit convoluted, but the essence can be captured in the following: my_frame = pd....
Daniel Marchand's user avatar
0 votes
0 answers
37 views

For example, in the dataframe below, I want to remove the top index (sum/lambda) so it prints in a cleaner fashion. I'm going to be then exporting that dataframe to excel.
Robert Criqui's user avatar
1 vote
0 answers
35 views

I made a pivot dataframe at pandas and it's columns are separated in two levels How can I remove the first level? import pandas as pd import matplotlib.pyplot as plt import numpy as np % matplotlib ...
Reza energy's user avatar
0 votes
0 answers
28 views

I want to remove some data from a Pandas dataframe and make it over. I tried using the drop function but this didnt work. It is unclear to me whether the data is a row or level. The picture below will ...
Alex's user avatar
  • 357
13 votes
2 answers
5k views

Screenshot of the query below: Is there a way to easily drop the upper level column index and a have a single level with labels such as points_prev_amax, points_prev_amin, gf_prev_amax, gf_prev_amin ...
hkhare's user avatar
  • 335
10 votes
2 answers
12k views

I have a dictionary dict contains many (more than 100) dataframes. Each dataframe contains two variable name and 'value_i'. For example, the first dataframe in this dictionary dict[1] looks like the ...
fly36's user avatar
  • 93
3 votes
4 answers
2k views

I have a dataframe much like the one in this question: Pandas: drop a level from a multi-level column index? cols = pd.MultiIndex.from_tuples([("a", "b"), ("a", "c")]) pd.DataFrame([[1,2], [3,4]], ...
MetaStack's user avatar
  • 3,848
3 votes
2 answers
3k views

I am plotting a multi-index columns DataFrame. What is the syntax to specify the column(s) to be plotted on secondary_y using the .plot method of pandas DataFrame? Setup import numpy as np import ...
FLab's user avatar
  • 7,546
0 votes
1 answer
2k views

Related to following question I asked earlier: Python pandas dataframe pivot only works with pivot_table() but not with set_index() and unstack() I have been able to pivot the following sample data ...
rp1's user avatar
  • 169
1 vote
1 answer
1k views

I have a pivot table that looks like this- 0 type A B C obs x NA 1 2 y 1 1 2 z 2 2 3 I want to reset the index to look like this- obs A B C x ...
mDe's user avatar
  • 107
1 vote
3 answers
286 views

Suppose I have the following dataframe : X Y ---+---+---+--- A | B | A | B --+---+---+---+--- 0 | 1 | 2 | 3 | 4 1 | 5 | 6 | 7 | 8 2 | 9 | 10| 11| 12 I want to split it based on the ...
Gambit1614's user avatar
  • 8,841
2 votes
1 answer
1k views

I have a pandas DataFrame like this: n = 6000 my_data = DataFrame ({ "Category" : np.random.choice (['cat1','cat2'], size=n) , "val_1" : np.random.randn(n) , "val_2" : [i for i ...
sparc_spread's user avatar
  • 10.9k

15 30 50 per page