Skip to main content
Filter by
Sorted by
Tagged with
Best practices
1 vote
2 replies
65 views

I am trying to merge two pandas dataframes together that have a MultiIndex on the columns. This works as expected when there are no duplicate columns, however when there are duplicate columns, it ...
Simon Pratt's user avatar
1 vote
1 answer
109 views

I have two DataFrames, data1 and data2, with 3-level multiindices. The first two levels are floats, and correspond to spatial coordinates (say longitude and latitude). The third level, time, is based ...
peich's user avatar
  • 33
2 votes
1 answer
87 views

I have made a boost multiindex of my GameObject, and I am trying to loop through and call non const functions on it. And I cannot for the life of me to get boost to stop giving long nasty compiler ...
user904542's user avatar
  • 7,087
0 votes
0 answers
48 views

I'm using alphalens.utils.get_clean_factor_and_forward_returns() to compute forward returns from a factor series and price DataFrame. But I'm hitting the following error: ValueError: Length mismatch: ...
Aboriginal's user avatar
0 votes
1 answer
54 views

I have a dataframe of 40000 row and 64 columns. The columns are indexed with a 2 level index (16 labels in level 0 and 4 in level 1), while the rows have a simple index. I want the columns labels of ...
user27243451's user avatar
2 votes
2 answers
88 views

I have a dataframe with a column multi-index, df1, with a datetime index and 2 levels: level 0, called Capitals, has columns A, B, C, and level 1, called Smalls, has columns a, b, c, d, e. Capitals A ...
AndysPythonStuff's user avatar
0 votes
1 answer
78 views

I want to create (for example) a small multi-index dataframe with 3 level index and one column of values. There will only be a handful of rows. Value Category Sub Category Sub Sub Category Machine ...
Tim's user avatar
  • 397
1 vote
1 answer
104 views

I have a dataframe whose index is a multiindex where axes[0] is the date, and axis[1] is the rank. Rank starts with 1 and ends at 100, but there can be a variable number of ranks in between as below. ...
dayum's user avatar
  • 1,105
1 vote
1 answer
66 views

I have the following DataFrame: df = pd.DataFrame({ "One_X": [1.1, 1.1, 1.1], "One_Y": [1.2, 1.2, 1.2], "Two_X": [1.11, 1.11, 1.11], "Two_Y": [1....
Mohamad Osama's user avatar
2 votes
1 answer
64 views

My understanding is that DataFrames do not support MultiIndexing, which generally does not pose much problems, but translating some pythonic habits to Julia poses difficulties. I wonder how one could ...
Roger V.'s user avatar
  • 803
1 vote
1 answer
691 views

Since Polars doesn't work with multi-index headers like Pandas does, I'd like to know if there's a native way to do the following: My current implementation has to go through Pandas first and then ...
Reveur's user avatar
  • 11
2 votes
2 answers
259 views

When running the snippet of example code below with pandas 2.2.3, I get an error saying KeyError: 'D' index = pd.MultiIndex.from_tuples( [('A', 1), ('A', 2), ('A', 3), ('B', 1), ('B', 2), ('B', 2)]...
X-L's user avatar
  • 19
0 votes
1 answer
71 views

I have a dataframe (output here: https://pastebin.com/7RCPsHet; can be read with pd.DataFrame.from_dict(orient='tight')) with two columns that I want the total of. They look like: Tiered ...
Long Vuong's user avatar
3 votes
2 answers
98 views

I have a dataframe with multi index as follows arrays = [ ["bar", "bar", "baz", "baz", "foo", "foo", "qux", "qux"], ...
plotmaster473's user avatar
4 votes
4 answers
120 views

For my given multi-indexed DataFrame: df = pd.DataFrame( np.random.randn(12), index=[ [1,1,2,3,4,4,5,5,6,6,7,8], [1,2,1,1,1,2,1,2,1,2,2,2], ] ) 0 1 1 1.667692 ...
Kyle Carow's user avatar
0 votes
1 answer
71 views

I need to write an algorithm that takes N points, and outputs all the possible 3-stars and triangles that are formed by the points. Here's an example for clarification. Let N = 4, then I have 4 choose ...
Ollie's user avatar
  • 117
1 vote
2 answers
68 views

Consider the following DataFrame: import pandas as pd arrays = [['A','A','B','B','C','C'],[1,1,3,3,5,5,],[2,2,4,4,6,6],[0.1,0.2,0.3,0.4,0.5,0.6]] index = pd.MultiIndex.from_arrays(arrays,names=('...
germ's user avatar
  • 1,759
1 vote
3 answers
142 views

I have a CSV file from a measurement device, that produces a bunch of values (Temperature, Rain and Wind) and gives some metadata for the device: Station, Hillside ID, 12345 elevation, 54321 units, °C,...
JC_CL's user avatar
  • 2,678
1 vote
1 answer
109 views

I have the following dataframe, mapping a one-to-many relationship between "courses" and "lessons": course_id course_name lesson_id lesson_title 0 0 ...
Afelium's user avatar
  • 65
0 votes
1 answer
47 views

I have a multiindex dataframe called 'prevtests', which for testing purposes I have added one entry to: tests fails thickness sample size pval 4 10 ...
Zoe Allen's user avatar
  • 137
0 votes
1 answer
77 views

I want to use python to read an Excel file and transform it into a different structure (Example). On the left side of the red marked area there are about 15 more columns The red marked area continues ...
Ben's user avatar
  • 3
0 votes
1 answer
123 views

My question is similar to this one : Filling in date gaps in MultiIndex Pandas Dataframe. I however want to group by A and B and then use a user defined range to re-index and each of these dates need ...
One_more_time's user avatar
0 votes
2 answers
107 views

Say I have a MultiIndex by MultiIndex DataFrame similar to the one generated here (in the real use case the list of races is dynamic and not known ahead of time): import random import pandas as pd ...
niltz's user avatar
  • 1,178
0 votes
0 answers
51 views

I have the multiindex dataframe (example below but not complete) named "pivot_dftable" and the code below displaying the analysis I need for it. I would like to understand why in the graph ...
Paulo Cortez's user avatar
2 votes
2 answers
112 views

I have two Dataframes. Dataframe1(df1): has 4 columns as shown below. X Y A( in days) B(sum) a aa 7 a bb 9 b aa 36 c dd 29 Column X and Column Y are strings and Column A in days and another column B ...
One_more_time's user avatar
0 votes
2 answers
96 views

Lets say we have this dummy data : dates=pd.date_range("2020-02-01","2021-02-01",freq="MS") features=["foo","bar"] cols=pd.MultiIndex.from_product([...
Nathan Keloglanian's user avatar
4 votes
4 answers
175 views

Consider the following multi-level column index dataframe: import numpy as np import pandas as pd arrays = [ ["A", "A", "B", "B"], ["one", &...
Andi's user avatar
  • 5,177
2 votes
1 answer
73 views

I have the following two DataFrames: df 100 101 102 103 104 105 106 107 108 109 0 1.0 1.0 1.0 1.0 1.0 1.0 1.0 1.0 1.0 1.0 1 1.0 2.0 3.0 4.0 5.0 6.0 7.0 8.0 9.0 10.0 2 ...
NicoH's user avatar
  • 1,415
1 vote
2 answers
121 views

I have an Excel file containing credit spread calculations for different credit ratings. The structure includes merged cells which create multi-level column headers. Here is an example of the ...
Forecaster's user avatar
0 votes
1 answer
65 views

list of dataframes (ex. dfs = [df1, df2, ...]) all dataframe columns is multiindex (ex. [("something", "id",), ("something", "age"), ...]) i want to set "...
bhnvx's user avatar
  • 25
0 votes
0 answers
36 views

I have a dataframe with a column multiindex and various data columns: id value1 value2 valuen name date foo 01-2000 No01 324 6575 ... bar 02-2000 No02 964 0982 ...
JC_CL's user avatar
  • 2,678
0 votes
1 answer
39 views

Suppose we have a DataFrame: data = {'person_id': ['person_a', 'person_a', 'person_b','person_b', 'person_c','person_c'], 'categorical_data': ['new', 'new', 'ok', 'bad', 'new', 'bad']} df = pd....
MrChomp's user avatar
1 vote
1 answer
30 views

If I build a dataframe like this arrays = [ np.array(["bar", "bar", "baz", "baz", "foo", "foo", "qux", "qux"]), ...
David's user avatar
  • 1,297
1 vote
1 answer
73 views

I posted this on reddit some days ago, but haven't received any response. Everything I've read online about the pandas MultiIndex makes it seem like a counterpart to a SQL composite index. Is this ...
user2153235's user avatar
  • 1,285
2 votes
1 answer
68 views

I have the following DataFrame with MultiIndex columns (the same applies to MultiIndex rows): import pandas as pd df = pd.DataFrame(columns=pd.MultiIndex.from_product([['A','B'],[1,2,3,4]]), ...
germ's user avatar
  • 1,759
0 votes
1 answer
58 views

I'm struggling with the creation of this DataFrame A B x y a 1 2 1 2 6 3 c 2 7 2 from these two dictionaries which seem sufficient: data = {'A': [2,6,7], 'B': [1,3,2]} ...
mins's user avatar
  • 7,784
4 votes
1 answer
920 views

I've a dataframe with a non-unique MultiIndex: A B L1 L2 7.0 7.0 -0.4 -0.1 8.0 5.0 -2.1 1.6 5.0 8.0 -1.8 -0.8 7.0 7.0 0.5 -1.2 NaN -1.1 -0.9 5.0 8.0 0.6 2.3 I want ...
mins's user avatar
  • 7,784
4 votes
2 answers
113 views

My understanding is MultiIndex.dropna() removes index entries for which at least one level is NaN, there are no conditions. However it seems if a previous groupby was used with dropna=False, it's no ...
mins's user avatar
  • 7,784
-1 votes
2 answers
38 views

Having a multi index dataframe of 3 levels (year, month and day) I want to keep the last day of every month, in the case below, on april 2024, only day 4 should be kept
Crovish's user avatar
  • 223
0 votes
0 answers
87 views

This question is similar to Pandas selecting by label sometimes return Series, sometimes returns DataFrame, however I didn't find a solution there. I have 2 dataframes read from CSV with a multi-index ...
N4ppeL's user avatar
  • 1,857
5 votes
1 answer
81 views

In this call to df.sort_index() on a MultiIndex dataframe, how to use func_2 for level two? func_1 = lambda s: s.str.lower() func_2 = lambda x: np.abs(x) m_sorted = df_multi.sort_index(level=['one', '...
mins's user avatar
  • 7,784
3 votes
2 answers
85 views

I have two multi-indexed pandas dataframes that look like this: >>> df1 = pd.DataFrame({ ... ('y1', '0'): [1, 2, 3], ... ('y2', '0'): [4, 5, 6], ... ('y11', '0'): [7, 8, 9], ... })...
Sai-Aakash Ramesh's user avatar
0 votes
1 answer
39 views

I have a multi-index column dataframe that also has date. I would like the columns to be as rows. For example: | A | A | B | B | | X | Y | X | Y | Date | | 1 | 2 | 3 | 4 | May-08 | And I need it to ...
ryeant's user avatar
  • 11
1 vote
1 answer
54 views

I am trying to harmonize the structure of two dataframes. They have the same columns except one of the dataframes which has had a df.compare() done to it so it is a multi index with "self" ...
Imakeweirdstuff's user avatar
2 votes
1 answer
69 views

After pivoting around two columns with a separate value column, I want a df with multiindex columns in a specific order, like so (please ignore that multi-2 and multi-3 labels are pointless in the ...
DrWhat's user avatar
  • 2,490
0 votes
1 answer
83 views

I have a dataframe as per the below with a multi index mx_dict = pd.read_excel('ABC Bookings.xlsx', header=[1,2], sheet_name=None) Excel file if useful: excel file mx = pd.concat(mx_dict.values(), ...
ips2k4's user avatar
  • 21
1 vote
1 answer
36 views

We start with this data: import numpy as np import pandas as pd data=pd.DataFrame(data=np.random.rand(10,5),columns=['headA','headB','tailA','tailB','tailC']) Now I want to perform a certain unstack ...
principal-ideal-domain's user avatar
3 votes
2 answers
74 views

Here is a minimal example: import pandas as pd import numpy as np np.random.seed(0) idx = pd.MultiIndex.from_product([[1,2,3], ['a', 'b', 'c'], [6, 7]]) df = pd.DataFrame(np.random.randn(18), index=...
Chachni's user avatar
  • 491
2 votes
1 answer
386 views

I want to be able to set multiple columns at once using a top level column indexer in a DataFrame with a MultiIndex column structure. Data Definition I am performing data processing using a DataFrame ...
Sam Beard's user avatar
  • 100
2 votes
3 answers
77 views

My raw data is as such level0 level1 level2 0 0 A foo 1 0 A bar 2 0 B foo 3 0 B foo 4 0 B foo 5 0 B bar 6 1 ...
jeff_new's user avatar
  • 551

1
2 3 4 5
57