Resetting Index on slice
See original GitHub issueCode Sample, a copy-pastable example if possible
# Your code here
df = data_index[data_index['ntorsions'] == 2]
Problem description
When slicing a dataframe, the index is not reset by default. This becomes an issue if you want to output that dataframe, combine that dataframe with other dataframes (good luck with that), or output the dataframe without two index columns.
Fixing this will not break code in the wild.
Expected Output
Index being correct - without the need to manually call reset_index over and over again. This is much more intuitive to end users.
-> At end of slice, call reset_index(drop = True) on the returned dataframe or current dataframe if you are slicing in-place.
Output of pd.show_versions()
loaded rc file /Users/jadolfbr/.matplotlib/matplotlibrc matplotlib version 1.5.1 verbose.level helpful interactive is False platform is darwin
INSTALLED VERSIONS
commit: None python: 2.7.10.final.0 python-bits: 64 OS: Darwin OS-release: 14.5.0 machine: x86_64 processor: i386 byteorder: little LC_ALL: None LANG: en_US.UTF-8
pandas: 0.18.1 nose: 1.3.7 pip: 9.0.1 setuptools: 20.3.1 Cython: None numpy: 1.11.1 scipy: 0.13.0b1 statsmodels: 0.6.1 xarray: None IPython: 4.1.2 sphinx: None patsy: 0.4.0 dateutil: 2.5.3 pytz: 2016.4 blosc: None bottleneck: None tables: None numexpr: None matplotlib: 1.5.1 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: None pandas_datareader: None
Issue Analytics
- State:
- Created 6 years ago
- Comments:7 (4 by maintainers)
Top GitHub Comments
you are not using pandas power at all. you are in fact making a big assumption that the data that you are dividing is exactly the same length and perfectly lines up. maybe that’s always true for you.
I would probably do something like this. In fact this is quite general and deals with missing labeled data.
This is a slightly different and IMHO better way of organizing things.
Thanks for the suggestion. Yes, this seems much better than what I was trying to do - use the indexes instead of fighting with them and trying to go around them. Makes sense. I guess this would make joining a whole lot more straightforward too. Awesome. Thanks for taking the time to write back.