Not working set_index with drop
See original GitHub issueCode Sample, a copy-pastable example if possible
from io import StringIO
from pandas import read_csv
dtf = read_csv(StringIO("DATE_TIME,A\n2/8/2015 6:00:30,1"))
print(dtf)
dtf.set_index(dtf.DATE_TIME, drop=True, inplace=True)
print(dtf.columns)
print(dtf)
Current output
DATE_TIME A
0 2/8/2015 6:00:30 1
Index(['DATE_TIME', 'A'], dtype='object')
DATE_TIME A
DATE_TIME
2/8/2015 6:00:30 2/8/2015 6:00:30 1
Expected Output
DATE_TIME A
0 2/8/2015 6:00:30 1
Index(['A'], dtype='object')
A
DATE_TIME
2/8/2015 6:00:30 1
output of pd.show_versions()
INSTALLED VERSIONS
------------------
commit: None
python: 3.5.1.final.0
python-bits: 64
OS: Darwin
OS-release: 15.5.0
machine: x86_64
processor: i386
byteorder: little
LC_ALL: None
LANG: None
pandas: 0.18.1
nose: None
pip: 8.1.2
setuptools: 20.6.7
Cython: None
numpy: 1.11.1
scipy: 0.16.1
statsmodels: None
xarray: None
IPython: 4.0.1
sphinx: None
patsy: None
dateutil: 2.5.3
pytz: 2016.6
blosc: None
bottleneck: None
tables: None
numexpr: None
matplotlib: 1.5.0
openpyxl: 2.3.5
xlrd: 1.0.0
xlwt: 1.0.0
xlsxwriter: None
lxml: None
bs4: 4.4.1
html5lib: None
httplib2: 0.9.2
apiclient: 1.5.0
sqlalchemy: None
pymysql: None
psycopg2: None
jinja2: 2.8
boto: None
pandas_datareader: None
None
Issue Analytics
- State:
- Created 7 years ago
- Comments:6 (5 by maintainers)
Top Results From Across the Web
Pandas set_index doesn't drop the column - Stack Overflow
set_index(df["col_1"]) this does not drop the column given that drop parameter is set to True by default. If I did the following df.set_index(" ......
Read more >pandas.DataFrame.set_index — pandas 1.5.2 documentation
Set the DataFrame index (row labels) using one or more existing columns or arrays (of the correct length). The index can replace the...
Read more >Pandas set index method explained with examples
The set index method takes keys, append, drop, inplace, and verify_intergrity as parameters and returns the data frame with index using one or...
Read more >How to Use the Pandas Set Index Method - Sharp Sight
The drop parameter enables you to specify whether or not the set_index method will “drop” the column that you set as the index....
Read more >Assign existing column to the DataFrame index with set_index()
How to use set_index(). Basic usage; Keep the specified column: drop; Assign multi-index; Keep the original index as a column; Change original ...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
thx, it looks to be a bug. if input is a
Series
sliced from original, corresponding column should be dropped.works fine if we pass column name.
any plans to fix this?