Skip to content

index_col result is unexpected when usecols is used to skip a column #12408

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
VelizarVESSELINOV opened this issue Feb 21, 2016 · 1 comment
Closed
Labels
Bug Duplicate Report Duplicate issue or pull request IO CSV read_csv, to_csv

Comments

@VelizarVESSELINOV
Copy link

Code Sample, a copy-pastable example if possible

"""Example of Pandas bug."""
from pandas import read_csv
try:
    from StringIO import StringIO
except ImportError:
    from io import StringIO

csv = """A, B, C
1, 2, 3"""


def message(msg):
    """Print message."""
    msg_len = len(msg) + 2
    print('-' * msg_len + '\n {}\n'.format(msg) + '-' * msg_len)

message('raw file')
print(csv)


df = read_csv(StringIO(csv), names=['A', 'B', 'C'], skiprows=1, header=None,
              usecols=['B', 'C'])


message('expected result after skiping column A')
print(df)

df = read_csv(StringIO(csv), names=['A', 'B', 'C'], skiprows=1, header=None,
              usecols=['B', 'C'], index_col='B')

message('not expected result, if use index with column B')
print(df)

Expected Output

Current output:

----------
 raw file
----------
A, B, C
1, 2, 3
----------------------------------------
 expected result after skiping column A
----------------------------------------
   B  C
0  2  3
-------------------------------------------------
 not expected result, if use index with column B
-------------------------------------------------
   B
B   
3  2

Expected output:

----------
 raw file
----------
A, B, C
1, 2, 3
----------------------------------------
 expected result after skiping column A
----------------------------------------
   B  C
0  2  3
-------------------------------------------------
 not expected result, if use index with column B
-------------------------------------------------
   C
B   
2  3

output of pd.show_versions()

INSTALLED VERSIONS

commit: None
python: 3.5.1.final.0
python-bits: 64
OS: Darwin
OS-release: 15.3.0
machine: x86_64
processor: i386
byteorder: little
LC_ALL: None
LANG: None

pandas: 0.17.1
nose: None
pip: 7.1.2
setuptools: 18.3.2
Cython: None
numpy: 1.10.1
scipy: 0.16.1
statsmodels: None
IPython: 4.0.1
sphinx: None
patsy: None
dateutil: 2.4.2
pytz: 2015.7
blosc: None
bottleneck: None
tables: None
numexpr: None
matplotlib: 1.5.0
openpyxl: 2.3.2
xlrd: None
xlwt: None
xlsxwriter: None
lxml: None
bs4: 4.4.1
html5lib: None
httplib2: None
apiclient: None
sqlalchemy: None
pymysql: None
psycopg2: None
Jinja2: 2.8

@jreback jreback added Bug Duplicate Report Duplicate issue or pull request IO CSV read_csv, to_csv labels Feb 22, 2016
@jreback
Copy link
Contributor

jreback commented Feb 22, 2016

this is a dupe of #9098

pull-requests to fix are welcome!

note that you data actually command and space delimited so not the best example

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug Duplicate Report Duplicate issue or pull request IO CSV read_csv, to_csv
Projects
None yet
Development

No branches or pull requests

2 participants