Skip to content

Reindex function applied to DataFrame over columns ignores method #14992

Closed
@gcbeltramini

Description

@gcbeltramini

Code Sample

>>> df = pd.DataFrame(data=[[11, 12, 13], [21, 22, 23], [31, 32, 33]],
                      index=[1, 3, 5],
                      columns=[1, 3, 5],
                      dtype=float)
>>> print(df)
      1     3     5
1  11.0  12.0  13.0
3  21.0  22.0  23.0
5  31.0  32.0  33.0

# Applying the reindex function to the columns, with the "ffill" method:
>>> print(df.reindex(columns=range(7), method='ffill'))
    0     1   2     3   4     5   6
1 NaN  11.0 NaN  12.0 NaN  13.0 NaN
3 NaN  21.0 NaN  22.0 NaN  23.0 NaN
5 NaN  31.0 NaN  32.0 NaN  33.0 NaN

# Workaround to get the expected output:
>>> print(df.T.reindex(index=range(7), method='ffill').T)
    0     1     2     3     4     5     6
1 NaN  11.0  11.0  12.0  12.0  13.0  13.0
3 NaN  21.0  21.0  22.0  22.0  23.0  23.0
5 NaN  31.0  31.0  32.0  32.0  33.0  33.0

Problem description

I want to apply the reindex function to the columns using the "ffill" method, but the holes are filled with NaN. The workaround is to transpose the DataFrame, apply the function and then transpose again.

Output of pd.show_versions()

INSTALLED VERSIONS

commit: None
python: 2.7.12.final.0
python-bits: 64
OS: Darwin
OS-release: 16.1.0
machine: x86_64
processor: i386
byteorder: little
LC_ALL: en_US.UTF-8
LANG: en_US.UTF-8

pandas: 0.18.1
nose: None
pip: 9.0.1
setuptools: 27.2.0
Cython: None
numpy: 1.11.1
scipy: None
statsmodels: None
xarray: None
IPython: 5.1.0
sphinx: None
patsy: None
dateutil: 2.6.0
pytz: 2016.10
blosc: None
bottleneck: None
tables: None
numexpr: None
matplotlib: None
openpyxl: None
xlrd: None
xlwt: None
xlsxwriter: None
lxml: None
bs4: None
html5lib: None
httplib2: None
apiclient: None
sqlalchemy: None
pymysql: None
psycopg2: None
jinja2: 2.8
boto: 2.38.0
pandas_datareader: None

Metadata

Metadata

Assignees

No one assigned

    Labels

    BugMissing-datanp.nan, pd.NaT, pd.NA, dropna, isnull, interpolateReshapingConcat, Merge/Join, Stack/Unstack, Explode

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions