2

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.

nucsit026
  • 652
  • 7
  • 16
JeeWoong Lee
  • 41
  • 1
  • 7

2 Answers2

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.

wjandrea
  • 28,235
  • 9
  • 60
  • 81
François B.
  • 1,096
  • 7
  • 19
-2

Try df.to_csv(filename, index=False)

tbhaxor Jan 14, 2020 at 9:27

wjandrea
  • 28,235
  • 9
  • 60
  • 81
rpagrawal
  • 17
  • 2
  • 4
  • 2
    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 https://stackoverflow.com/questions/21256013 (which has an accepted, correct, answer) – Joshua Voskamp Jan 09 '23 at 21:28