Questions tagged [multi-index]

A multi-index (also known as a hierarchical index) allows the manipulation of higher-dimensional data in a 2-dimensional tabular structure.

A multi-index exists when an indexing column (or row) of a tabular structure contains more than one line. The use of layered indexing enables one to effectively store and manipulate arbitrarily high dimension data in a 2-dimensional tabular structure 1. This is also called "hierarchical" or "multi-level" indexing.

2771 questions
1
vote
2 answers

Sum duplicated rows on a multi-index pandas series and insert zeros for missing categories

this question is very similar to the one here: Sum duplicated rows on a multi-index pandas dataframe Except it is for a Pandas Series, not a Pandas DataFrame and the answers given and accepted for a DataFrame are not working on my Series. Say I have…
Mark Keane
  • 984
  • 2
  • 11
  • 26
1
vote
1 answer

Performing Operations on Multi-Indexed data based on Indices

I have a 2 level multi-indexed (on X and Y) data frame that looks like this: df=( X1 Y1 Z1 Z2 Y2 Z3 Z3 Z4 X2 Y3 Z5) And I want to do some operation on Z based on the values of X…
1
vote
1 answer

Pandas groupby rows into list and sum

I have a multi-index pandas dataframe with the below data: F M 0 5 10 30 x y a1 0 1 0 1 a2 1 0 0 0 a3 0 1 0 1 a4 0 1 0 2 x1 y1 a1 0 1 1 4 a2 0 1 0 1 a3 1 1 0 1 …
sunny
  • 708
  • 11
  • 23
1
vote
1 answer

Python: properly construct, write and read MultiIndex pd to csv

I would like to generate a pandas dataframe with several columns, each of them having more and different sub-columns. Then I want to write it to a csv and read from it, maintaining the indexing right. Here's an exemple: col_1 =…
Marco Di Gennaro
  • 395
  • 1
  • 3
  • 15
1
vote
3 answers

Mask dataframe with another multi-indexed Series

I have a Dataframe that I would like to mask (convert to NaN) with the boolean values of a multi-indexed Series where the multi-index of the Series are also the column names in the Dataframe. For example, if df is: df = pd.DataFrame({ 'A': (188,…
PedroA
  • 1,803
  • 4
  • 27
  • 50
1
vote
1 answer

filter out specific dates in list from multiindex

I have a multi index data in which i would like to filter out a list of specific dates e.g. : date_list=[Timestamp('2018-05-19 00:00:00'), Timestamp('2018-06-24 00:00:00'), Timestamp('2014-11-12 00:00:00'), Timestamp('2015-11-11 00:00:00'), …
Maths12
  • 852
  • 3
  • 17
  • 31
1
vote
1 answer

pandas: MultiIndex not showing when plotting DataFrame

I am plotting the following pandas MultiIndex DataFrame: print(log_returns_weekly.head()) AAPL MSFT TSLA FB GOOGL Date Date 2016 1 -0.079078 0.005278 -0.155689 …
Jayjay95
  • 199
  • 9
1
vote
1 answer

Pandas DataFrame --> GroupBy --> MultiIndex Process

I'm trying to restructure a large DataFrame of the following form as a MultiIndex: date store_nbr item_nbr units snowfall preciptotal event 0 2012-01-01 1 1 0 0.0 0.0 0.0 1 2012-01-01 1 …
OJT
  • 887
  • 1
  • 10
  • 26
1
vote
1 answer

Python: Balance a dataset for regression analysis (rearranging dataset and filling blank categories)

I have a dataset ( df2 ) that looks as follows: total_n ind_n4 year city_code 9 2003 a 236 2004 a 520 54 2002 b 167 2004 b …
PAstudilloE
  • 659
  • 13
  • 24
1
vote
1 answer

Quadratic n term equation using multiindex

I have two DFs which I would like to use to calculate the following: w(ti,ti)*a(ti)^2 + w(tj,tj)*b(sj,tj)^2 + 2*w(si,tj)*a(ti)*b(tj) The above uses two terms (a,b). w is the weight df where i and j are index and column spaces pertaining to the Tn…
RealRageDontQuit
  • 405
  • 4
  • 17
1
vote
2 answers

Search optimization with pandas multi-index

I want to know if there is a way to optimize a search that I am doing. I have a multi-index (3 levels) dataframe df, like this: IndexID IndexDateTime IndexAttribute ColumnA ColumnB 1 2015-02-05 8 A B 1 …
Soutuyo
  • 106
  • 10
1
vote
2 answers

Filtering on Column by a Value That Changes Depending on an MultiIndex Level

Complicated title but pretty simple problem. I have a DataFrame with a MultiIndex: I'd like rows of the frame above but the 'Filter Column' must be greater than or equal to the values in the filter_value series below. filter_value = Series([1, 3],…
rhaskett
  • 1,864
  • 3
  • 29
  • 48
1
vote
1 answer

Optimization problem with Pandas apply and multiIndex search

So, I was wondering if I am doing this correctly, because maybe there is a much better way to do this and I am wasting a lot of time. I have a 3 level index dataframe, like this: IndexA IndexB IndexC ColumnA ColumnB A B C1 HiA …
Soutuyo
  • 106
  • 10
1
vote
1 answer

Pandas Dataframe multiindex

I'm new to Python, Pandas, Dash, etc. I'm trying to structure a dataframe so I can create some dash components for graphing that will allow the user to see and filter data. At the top are aggregation characteristics, the first 3 are required and…
David Hill
  • 45
  • 5
1
vote
2 answers

How to calculate with previous values in a Pandas MultiIndex DataFrame?

I have the following MultiIndex dataframe. Close ATR Date Symbol 1990-01-01 A 24 2 1990-01-01 B 72 7 1990-01-01 C 40 3.4…
mmaarrttoonn
  • 119
  • 9