我正在尝试
我已经卡了一天,非常感谢您的帮助。以下是我发布的原始问题和我的代码: ValueError: cannot reindex from a duplicate axis Pandas。我只想知道这是否是一个问题。
我的代码:
concat
一些timeseries
。对于某些数据集,这很有效。我的timeseries
以date
作为索引。现在,对于一些ts.size
相同的数据集,pd.concat
可以完美地工作。但是,当timeseries
之间的size
不同时,我会收到错误消息:cannot reindex from a duplicate axis
。因此,我认为这是由于size
的差异导致的。如果是这样,那么我应该用零填充timeseries
吗?
ts.head()
:date
2017-03-09 24.6245
2017-03-10 24.5765
2017-03-13 24.5767
2017-03-14 24.5344
2017-03-15 24.5440
我已经卡了一天,非常感谢您的帮助。以下是我发布的原始问题和我的代码: ValueError: cannot reindex from a duplicate axis Pandas。我只想知道这是否是一个问题。
我的代码:
def get_adj_nav(self, fund_id):
df_nav = read_frame(
super(__class__, self).filter(fund__id=fund_id, nav__gt=0).exclude(fund__account_class=0).order_by(
'valuation_period_end_date'), coerce_float=True,
fieldnames=['income_payable', 'valuation_period_end_date', 'nav', 'outstanding_shares_par'],
index_col='valuation_period_end_date')
df_dvd, skip = self.get_dvd(fund_id=fund_id)
df_nav_adj = calculate_adjusted_prices(
df_nav.join(df_dvd).fillna(0).rename_axis({'payout_per_share': 'dividend'}, axis=1), column='nav')
return df_nav_adj
def json_total_return_table(request, fund_account_id):
ts_list = []
for fund_id in Fund.objects.get_fund_series(fund_account_id=fund_account_id):
if NAV.objects.filter(fund__id=fund_id, income_payable__lt=0).exists():
ts = NAV.objects.get_adj_nav(fund_id)['adj_nav']
ts.name = Fund.objects.get(id=fund_id).account_class_description
ts_list.append(ts.copy())
print(ts)
df_adj_nav = pd.concat(ts_list, axis=1) # ====> Throws error
cols_to_datetime(df_adj_nav, 'index')
df_adj_nav = ffn.core.calc_stats(df_adj_nav.dropna()).to_csv(sep=',')
merge()
链接。 - DoDoSmarts