Skip to content

Updating a DataFrame by iteratively indexing into a columns #7084

Closed
@Jenders74

Description

@Jenders74

I am initializing a DataFrame with 0 and then update it by iteratively indexing into indvidual columns. The behavior of my code has changed with pandas 0.13.0 such that resulting DataFrame out[['A']] remains 0 but series out['A'] has the correct values:

>>> print out[['A']]
            A
2014-05-07  0
2014-05-08  0
2014-05-09  0

 >>> print out['A']
2014-05-07    600
2014-05-08    600
2014-05-09    600

Is this a bug?

import pandas
#initialize a DataFrame with 0 values
out = pandas.DataFrame({'A': [0, 0, 0]})
out.index = pandas.date_range('5/7/2014', '5/9/2014')

#DataFrame to update out with
df = pandas.DataFrame({'C': ['A', 'A', 'A'], 'D': [100, 200, 300]})

#loop through df to update out
for ix, row in df.iterrows():
    six = pandas.Timestamp('5/7/2014')
    eix = pandas.Timestamp('5/9/2014')
    out[row['C']][six:eix] = out[row['C']][six:eix] + row['D']

print out
print out[['A']]
print out['A']
INSTALLED VERSIONS
------------------
Python: 2.7.6.final.0
OS: Windows
Release: 7
Processor: Intel64 Family 6 Model 58 Stepping 9, GenuineIntel
byteorder: little
LC_ALL: None
LANG: en_US

pandas: 0.13.0
Cython: 0.20
Numpy: 1.7.1
Scipy: 0.12.0
statsmodels: 0.5.0
    patsy: 0.2.1
scikits.timeseries: Not installed
dateutil: 1.5
pytz: 2013.9
bottleneck: 0.7.0
PyTables: 3.1.0rc2
    numexpr: 2.2.2
matplotlib: 1.3.1
openpyxl: 1.8.2
xlrd: 0.9.2
xlwt: 0.7.5
xlsxwriter: Not installed
sqlalchemy: Not installed
lxml: Not installed
bs4: 4.3.2
html5lib: Not installed
bigquery: Not installed
apiclient: Not installed

Metadata

Metadata

Assignees

No one assigned

    Labels

    BugIndexingRelated to indexing on series/frames, not to indexes themselves

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions