multi-index

pandas merge with MultiIndex, when only one level of index is to be used as key

不问归期 提交于 2021-02-20 17:56:35
问题 I have a data frame called df1 with a 2-level MultiIndex (levels: '_Date' and _'ItemId'). There are multiple instances of each value of '_ItemId', like this: _SomeOtherLabel _Date _ItemId 2014-10-05 6588921 AA 6592520 AB 6836143 BA 2014-10-11 6588921 CA 6592520 CB 6836143 DA I have a second data frame called df2 with '_ItemId' used as a key (not the index). In this df, there is only one occurrence of each value of _ItemId: _ItemId _Cat 0 6588921 6_1 1 6592520 6_1 2 6836143 7_1 I want to

Boost::Multi-index for nested lists

不想你离开。 提交于 2021-02-11 13:10:13
问题 How to implement Boost::Multi-index on a list of lists I have a hierarchical tree as follows: typedef std::list<struct obj> objList // the object list typedef std::list<objList> topLevelList // the list of top-level object lists struct obj { int Id; // globally unique Id std::string objType; std::string objAttributes; .... topLevelList childObjectlist; } At the top-level, I have a std::list of struct obj Then, each of these top-level obj can have any number of child objects, which are

Pandas column multi-index to rows

女生的网名这么多〃 提交于 2021-02-11 07:11:54
问题 I'm using yfinance to download price history for multiple symbols, which returns a df with multiple indexes. For example: import yfinance as yf df = yf.download(tickers = ['AAPL', 'MSFT'], period = '2d') A similar dataframe could be constructed without yfinance like: import pandas as pd pd.options.display.float_format = '{:.2f}'.format import numpy as np attributes = ['Adj Close', 'Close', 'High', 'Low', 'Open', 'Volume'] symbols = ['AAPL', 'MSFT'] dates = ['2020-07-23', '2020-07-24'] data =

Pandas column multi-index to rows

◇◆丶佛笑我妖孽 提交于 2021-02-11 07:10:21
问题 I'm using yfinance to download price history for multiple symbols, which returns a df with multiple indexes. For example: import yfinance as yf df = yf.download(tickers = ['AAPL', 'MSFT'], period = '2d') A similar dataframe could be constructed without yfinance like: import pandas as pd pd.options.display.float_format = '{:.2f}'.format import numpy as np attributes = ['Adj Close', 'Close', 'High', 'Low', 'Open', 'Volume'] symbols = ['AAPL', 'MSFT'] dates = ['2020-07-23', '2020-07-24'] data =

Pandas column multi-index to rows

烂漫一生 提交于 2021-02-11 07:09:59
问题 I'm using yfinance to download price history for multiple symbols, which returns a df with multiple indexes. For example: import yfinance as yf df = yf.download(tickers = ['AAPL', 'MSFT'], period = '2d') A similar dataframe could be constructed without yfinance like: import pandas as pd pd.options.display.float_format = '{:.2f}'.format import numpy as np attributes = ['Adj Close', 'Close', 'High', 'Low', 'Open', 'Volume'] symbols = ['AAPL', 'MSFT'] dates = ['2020-07-23', '2020-07-24'] data =

multiindex selecting in pandas

扶醉桌前 提交于 2021-02-10 03:26:58
问题 I have problems understanding multiindex selecting in pandas. 0 1 2 3 first second third C one mean 3 4 2 7 std 4 1 7 7 two mean 3 1 4 7 std 5 6 7 0 three mean 7 0 2 5 std 7 3 7 1 H one mean 2 4 3 3 std 5 5 3 5 two mean 5 7 0 6 std 0 1 0 2 three mean 5 2 5 1 std 9 0 4 6 V one mean 3 7 3 9 std 8 7 9 3 two mean 1 9 9 0 std 1 1 5 1 three mean 3 1 0 6 std 6 2 7 4 I need to create new rows: - 'CH' : ['CH',:,'mean'] => ['C',:,'mean'] - ['H',:,'mean'] - 'CH' : ['CH',:,'std'] => (['C',:,'std']**2 + [

multiindex selecting in pandas

一个人想着一个人 提交于 2021-02-10 03:15:59
问题 I have problems understanding multiindex selecting in pandas. 0 1 2 3 first second third C one mean 3 4 2 7 std 4 1 7 7 two mean 3 1 4 7 std 5 6 7 0 three mean 7 0 2 5 std 7 3 7 1 H one mean 2 4 3 3 std 5 5 3 5 two mean 5 7 0 6 std 0 1 0 2 three mean 5 2 5 1 std 9 0 4 6 V one mean 3 7 3 9 std 8 7 9 3 two mean 1 9 9 0 std 1 1 5 1 three mean 3 1 0 6 std 6 2 7 4 I need to create new rows: - 'CH' : ['CH',:,'mean'] => ['C',:,'mean'] - ['H',:,'mean'] - 'CH' : ['CH',:,'std'] => (['C',:,'std']**2 + [

Pandas Multiindex Groupby aggregate column with value from another column

邮差的信 提交于 2021-02-08 08:41:13
问题 I have a pandas dataframe with multiindex where I want to aggregate the duplicate key rows as follows: import numpy as np import pandas as pd df = pd.DataFrame({'S':[0,5,0,5,0,3,5,0],'Q':[6,4,10,6,2,5,17,4],'A': ['A1','A1','A1','A1','A2','A2','A2','A2'], 'B':['B1','B1','B2','B2','B1','B1','B1','B2']}) df.set_index(['A','B']) Q S A B A1 B1 6 0 B1 4 5 B2 10 0 B2 6 5 A2 B1 2 0 B1 5 3 B1 17 5 B2 4 0 and I would like to groupby this dataframe to aggregate the Q values (sum) and keep the S value

Pandas error: Writing as Excel with a MultiIndex is not yet implemented

守給你的承諾、 提交于 2021-02-08 06:40:55
问题 I have a pandas data frame that I create as follows: stats_matrix= #A list containing my data myindex=['','event 1','event 2','event 3','event 4','event 5','event 6','event 7','event 8','event 9','event 10'] #List used for indexing rows column_names=['Failed 1st Stage','% Failed 1st Stage','Active 1st Stage','% Active 1st Stage','Failed 2nd Stage','% Failed 2nd Stage','Failed 1st & 2nd','% Failed 1st & 2nd','Active 2nd Stage','% Active 2nd Stage','Total failed','% Total failed ','Total active

easy multidimensional numpy ndarray to pandas dataframe method?

二次信任 提交于 2021-02-07 09:17:12
问题 Having a 4-D numpy.ndarray, e.g. myarr = np.random.rand(10,4,3,2) dims={'time':1:10,'sub':1:4,'cond':['A','B','C'],'measure':['meas1','meas2']} But with possible higher dimensions. How can I create a pandas.dataframe with multiindex, just passing the dimensions as indexes, without further manual adjustments (reshaping the ndarray into 2D shape)? I can't wrap my head around the reshaping, not even really in 3 dimensions quite yet, so I'm searching for an 'automatic' method if possible. What