4

This is just a simple code that can take out some dataframes by using input dates. It works right, but my issues has suddenly appeared once more.

import matplotlib.pyplot as plt
import numpy as np
import pandas as pd
import datetime

plt.rc('font', family = 'Malgun Gothic')
df = pd.read_csv('seoul.csv', encoding = 'cp949', index_col=False)
df.style.hide_index()
del df['지점']

a = input("날짜 입력 yyyy-mm-dd: ")
b = input("날짜 입력 yyyy-mm-dd: ")

df['날짜'] = pd.to_datetime(df['날짜'])
mask = (df['날짜']>=a) & (df['날짜']<=b)
df.loc[mask]

And this is the result.

The result

How can I remove these numbers?(the row that I point out with a red box)

oh edit: change index_col=0 is not work since some of rows are in a different level.

5
  • Try df.to_csv(filename, index=False) Commented Jan 14, 2020 at 9:27
  • 2
    you can use d.reset_index(drop=True) to reset it, but you can't remove it, if you remove the index how you access ? Commented Jan 14, 2020 at 9:27
  • 1
    you have to call the Styler.hide_index each time you want to hide your index Commented Jan 14, 2020 at 9:33
  • huh yeah that is true lol Commented Jan 14, 2020 at 9:43
  • Does this answer your question? Pandas dataframe hide index functionality? Commented Jan 9, 2023 at 21:30

2 Answers 2

1

The index is the way the rows are identified. You can't remove it.
You can only reset it, if you make some selection and want to reindex your dataframe.

df = df.reset_index(drop=True)

If the argument drop were set to False, the indexes would come in an additional column named index.

Sign up to request clarification or add additional context in comments.

2 Comments

this changes my index to 0, it does not completely gets ommited out of the result
@Gel As they said, "You can't remove it. You can only reset it"
-2

Try df.to_csv(filename, index=False)

tbhaxor Jan 14, 2020 at 9:27

1 Comment

This is a copy-paste of a comment from another user on the question, which doesn't address the question. Incidentally, the question is a duplicate of stackoverflow.com/questions/21256013 (which has an accepted, correct, answer)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.