add a field in pandas dataframe with MultiIndex columns

后端 未结 4 720
长发绾君心
长发绾君心 2021-02-06 00:00

i have looked for an answer to this question as it seems pretty simple, but have not been able to find anything yet. Apologies if I missed something. I have pandas version 0.1

4条回答
  •  长情又很酷
    2021-02-06 00:20

    I don't know how to do the broadcasting you want but for strict assignment this should do it:

    dftst[(('GOOG', 'avg_close'))] = 7 
    

    More specifically but still without broadcasting:

    for tic in cols_1:
       dftst[(tic, 'avg_close')] = pandas.rolling_mean(dftst[(tic, 'close')],5) 
    

提交回复
热议问题