Skip to content Skip to sidebar Skip to footer

Valueerror: Cannot Reindex From A Duplicate Axis Pandas

So I have a an array of timeseries` that are generated based on a fund_id: def get_adj_nav(self, fund_id): df_nav = read_frame( super(__class__, self).filter(fund__id=f

Solution 1:

Perhaps something like this would work. I've added the fund_id to the dataframe and reindexed it to the valuation_period_end_date and fund_id.

# Only fourth line above error.
ts = (
    NAV.objects.get_adj_nav(fund_id['adj_nav']
    .to_frame()
    .assign(fund_id=fund)
    .reset_index()
    .set_index(['valuation_period_end_date', 'fund_id']))

And then stack with axis=0, group on the date and fund_id (assuming there is only one unique value per date and fund_id, you can take the first value), then unstack fund_id to pivot it as columns:

df_adj_nav = (
    pd.concat(ts_list, axis=0)
    .groupby(['valuation_period_end_date', 'fund_id'])
    .first()
    .to_frame()
    .unstack('fund_id'))

Post a Comment for "Valueerror: Cannot Reindex From A Duplicate Axis Pandas"