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
1 answer

Multi-index - get maximum of second index for each first index

I have dataframe with a multi-index which looks like the following: ts ts2 2018-05-24 23:00:00 2018-05-24 00:00:00 5 2018-05-24 00:15:00 4 2018-05-24 00:30:00 6 …
Johannes
  • 147
  • 3
  • 14
1
vote
2 answers

Split DataFrame column into two + MultiIndex

I have DataFrame flows representing people crossing borders flows = DataFrame([[1,2],[3,4]], index=['Monday', 'Tuesday'], columns=['CZ>DE', 'HU>AT']) CZ>DE HU>AT Monday 1 2 Tuesday 3 4 I would like to split each…
PyJan
  • 88
  • 5
1
vote
2 answers

operations on mutliindex dataframe

I would like to add columns into a Pandas multiindex dataframe, which will contain the result of an operation performed on other columns. I have a dataframe similar to this one: first bar baz second one two one two A 5 2 9 2 …
1
vote
2 answers

How to reorder multi-index columns in Pandas?

df=pd.DataFrame({'Country':["AU","GB","KR","US","GB","US","KR","AU","US"],'Region Manager':['TL','JS','HN','AL','JS','AL','HN','TL','AL'],'Curr_Sales':…
Boomshakalaka
  • 521
  • 1
  • 6
  • 19
1
vote
1 answer

looping through a dataframe to return rows based on 2 indexes in python

I have a multi indexed dataframe sorted by name and date and time and i would like to go through the dataframe to select the latest(time wise) row for each day. see example below: name time code Trudy 1/2/2018 2:36PM …
John_gis
  • 117
  • 8
1
vote
1 answer

Divide subset of multiindex Dataframe by a value from dictionary

I have multiindex DataFrame and a dictionary. I need to divide all numerical values in the DF by the number from the dictionary when the dictionary key corestponding with the 0 level index. Here is my code -- all I get is NaN values. Thanks for…
BoB
  • 129
  • 2
  • 9
1
vote
2 answers

Using idxmax on a hierarchical dataframe

I'm trying to find the index of the maximum values in multiple columns in a multi-index Pandas dataframe. Kommune Upplands Vallentuna... Kiruna Year Party 1973 M 0.9 29.2 ... 20 KD 15 …
dustbunny
  • 67
  • 5
1
vote
1 answer

Filter rows from DataFrame by multi-index column slice predicate

I have a dataframe with a multi-index for the columns defined as follows: import numpy as np import pandas as pd index = range(4) columns = pd.MultiIndex.from_product([ ['A0', 'B0'], ['A1', 'B1'], ['A2', 'B2'] ]) data =…
tiefenauer
  • 669
  • 7
  • 19
1
vote
1 answer

Import multi-indexed data without creating integer column names

I have an issue importing data from an excel file with nested column titles. Several column names are integers and I would like to have them as strings. Let's say I have this table in excel: | | 1 | string_name | …
hendriksc1
  • 59
  • 5
1
vote
2 answers

How can I take one of my pandas heirarchical indexes and one hot encode it?

I have created a multi-hierarchical index from frames that have been indexed by time: original_thing time day_1 day_2 day_3 day_4 2018-05-24 20:00:00 0 0 1 0 2018-05-25 00:00:00 0 0 0 1 2018-05-25…
1
vote
0 answers

Pandas multiindex dataframe .columns not working

I have a multiindex dataframe: unique cat numerical c f b d a e 0 2 5 1 3 0 4 1 8 11 7 9 6 10 2 14 17 13 15 12 16 I'm trying to get the column names under…
Nathan Tew
  • 432
  • 1
  • 5
  • 21
1
vote
2 answers

How to extract specific data from multiindex dataframe (Yahoo stock data)

Could someone give me a quick/clear lesson on grabbing specific data points in the multiindex dataframe below? I've been looking at tutorials all day, but none have been very helpful. This should be simple for someone who knows Pandas. How can I…
sslack88
  • 1,403
  • 3
  • 10
  • 15
1
vote
1 answer

Adding a MultiIndex Summary Column at the Beginning of a DataFrame

If I have a Dataframe and I'd like to insert a summary column at the beginning I can run df.insert(0, 'Average', df.mean(axis='columns')) Say I have a MultiIndexed dataframe of the form df = pd.DataFrame() for l1 in ('a', 'b'): for l2 in…
rhaskett
  • 1,864
  • 3
  • 29
  • 48
1
vote
1 answer

Rolling mean (that extends its window) on grouped multi-index

I have a multi-index based on dates and times (grouped by times). Data looks like this: r2 var_v2x _s date time 2017-10-02 08:05:00 0.00000031 0.00008784 …
Maeaex1
  • 703
  • 7
  • 36
1
vote
1 answer

Want MultiIndex for rows and columns with read_csv

My .csv file looks like: Area When Year Month Tickets City Day 2015 1 14 City Night 2015 1 5 Rural Day 2015 1 18 Rural Night 2015 1 21 Suburbs Day 2015 1 15 Suburbs…
RandyB
  • 133
  • 1
  • 3
  • 14
1 2 3
99
100