0

我有 2 个索引类型的数据框:Datatimeindex,我想将一行复制到另一行。数据框是:

变量:df

DateTime
2013-01-01 01:00:00    0.0
2013-01-01 02:00:00    0.0
2013-01-01 03:00:00    0.0
....
Freq: H, Length: 8759, dtype: float64

变量:消费_年

Potência Ativa  ...    Costs
Datetime                             ...         
2019-01-01 00:00:00       11.500000  ...  1.08874
2019-01-01 01:00:00        6.500000  ...  0.52016
2019-01-01 02:00:00        5.250000  ...  0.38183
2019-01-01 03:00:00        5.250000  ...  0.38183

[8760 rows x 5 columns]

这是我的代码:

mc.run_model(tmy_data)

df=round(mc.ac.fillna(0)/1000,3)

consumption_year['PVProduction'] = df.iloc[:,[1]] #1
consumption_year['PVProduction'] = df[:,1] #2

我正在尝试将 df 的第二列复制到 consumer_year 数据框中的新列,但这些以前的经验都没有奏效。查看索引,我发现 3 个主要差异:

  1. 年(2013 年和 2019 年)
  2. 开始时间:01:00 和 00:00
  3. 长度:8760 和 8759

在将一行复制到另一行之前,我是否需要先解决这 3 个差异(使 df 的日期时间等于 consumer_year)?如果是这样,您能否为我提供解决这些差异的解决方案。

这些是错误:

1: consumption_year['PVProduction'] = df.iloc[:,[1]] 
 raise IndexingError("Too many indexers")
pandas.core.indexing.IndexingError: Too many indexers

2: consumption_year['PVProduction'] = df[:,1]
 raise ValueError("Can only tuple-index with a MultiIndex")
ValueError: Can only tuple-index with a MultiIndex
4

1 回答 1

0

您可以将两个数据框合并在一起。

pd.merge(df, consumption_year, left_index=True, right_index=True, how='outer')  
于 2020-07-01T10:04:20.307 回答