Linked Questions
27 questions linked to/from Pandas: drop a level from a multi-level column index?
0
votes
2
answers
865
views
How to convert column index to column name in pandas? [duplicate]
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=('...
0
votes
0
answers
240
views
Python: using agg() function in pandas avoiding mulitple column names [duplicate]
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 = {'...
2
votes
1
answer
67
views
MultiIndex DataFrame to a Standard index DF [duplicate]
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 ...
1
vote
1
answer
58
views
How to remove a row of columns from a dataframe [duplicate]
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....
0
votes
0
answers
37
views
Is there a way to remove one of the indexes when printing a dataframe in pandas? [duplicate]
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.
1
vote
0
answers
35
views
remove an item form levels of pivot data frame at pandas [duplicate]
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 ...
0
votes
0
answers
28
views
How to get rid of a level in pandas dataframe? [duplicate]
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 ...
13
votes
2
answers
5k
views
Pandas: Is there a way to use something like 'droplevel' and in process, rename the other level using the dropped level labels as prefix/suffix?
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 ...
10
votes
2
answers
12k
views
How to merge all data-frames in a dictionary in Python [duplicate]
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 ...
3
votes
4
answers
2k
views
how to drop all columns under a nested column in pandas
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]], ...
3
votes
2
answers
3k
views
Pandas DataFrame plot: specify column from MultiIndex for secondary_y
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 ...
0
votes
1
answer
2k
views
python pandas set_index() and unstack results in columns with underscores in hive but pivot_table() works
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 ...
1
vote
1
answer
1k
views
Change index of a pivoted table?
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 ...
1
vote
3
answers
286
views
Split Multilevel dataframe into different csv files
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 ...
2
votes
1
answer
1k
views
Pandas: Aggregating and applying multiple functions to same column
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 ...