到目前为止,我已经用python创建了一个数据框,如下所示:
NEG_00_04 NEG_04_08 NEG_08_12 NEG_12_16 NEG_16_20 NEG_20_24 \
datum_von
2017-10-10 0 0 0 0 0 0
2017-10-10 0 0 0 0 0 0
2017-10-10 0 0 0 0 0 0
2017-10-10 0 0 0 0 0 0
2017-10-10 0 0 0 0 0 0
2017-10-10 0 0 0 0 0 0
2017-10-10 0 0 0 0 0 0
2017-10-10 0 0 0 0 0 0
2017-10-10 0 0 0 0 0 0
2017-10-10 0 0 0 0 0 0
2017-10-10 0 0 0 0 0 0
2017-10-10 0 0 0 0 0 0
2017-10-11 0 0 0 0 0 0
2017-10-11 0 0 0 0 0 0我想用一些操作填充这个数据框。我正在尝试使用以下代码,但它不起作用。
prod = 0
dias = 0
x = 0
for prod in Products:
for dias in range(len(df_.index)):
df_.loc['dias']['prod'] = 1这很简单,但是我不太明白如何使用嵌套循环来填充这个数据frame.Also,我尝试了这个解决方案:
for prod in Products:
for dias in range(len(df_.index)):
df_.loc[dias][prod] = 1我的错误是:**TypeError: cannot do label indexing on <class 'pandas.indexes.base.Index'> with these indexers [0] of <type 'int'>**
**KeyError: 'the label [dias] is not in the [index]'**发布于 2017-10-25 21:16:32
我想通了
for prod in Products:
if k == len(Products):
break
for dias in y:
df_.ix[dias, prod] = 3
k=k+1https://stackoverflow.com/questions/46931785
复制相似问题