皆さん、お世話になります。
初歩的な質問になるのですがご教示ください。
jupyter notebook
anaconda
で勉強中です。
サイトを見ながらdataframeを作っていじろうとしたらエラーが出ます。
下記、コードです。
どうもindexが上手くいってないようなのですが…
どうすれば良いでしょうか?
import pandas as pd
import matplotlib.pyplot as plt
import datetime as dt
import numpy as np
#2018年のデータフレームを準備
start_data="2018-6-1"
end_data="2018-6-30"
df=pd.DataFrame(index=pd.date_range(start_data,end_data))
#dfの中身確認
df
2018-06-01
2018-06-02
2018-06-03
2018-06-04
2018-06-05
2018-06-06
2018-06-07
2018-06-08
2018-06-09
2018-06-10
2018-06-11
2018-06-12
2018-06-13
2018-06-14
2018-06-15
2018-06-16
2018-06-17
2018-06-18
2018-06-19
2018-06-20
2018-06-21
2018-06-22
2018-06-23
2018-06-24
2018-06-25
2018-06-26
2018-06-27
2018-06-28
2018-06-29
2018-06-30
#2018-06-01の削除
df.drop("2018-06-01)
エラー
ValueError Traceback (most recent call last)
<ipython-input-33-8cc9d365739b> in <module>()
----> 1 df.drop("2018-06-01")
C:\ProgramData\Anaconda3\lib\site-packages\pandas\core\generic.py in drop(self, labels, axis, index, columns, level, inplace, errors)
2528 for axis, labels in axes.items():
2529 if labels is not None:
-> 2530 obj = obj._drop_axis(labels, axis, level=level, errors=errors)
2531
2532 if inplace:
C:\ProgramData\Anaconda3\lib\site-packages\pandas\core\generic.py in _drop_axis(self, labels, axis, level, errors)
2560 new_axis = axis.drop(labels, level=level, errors=errors)
2561 else:
-> 2562 new_axis = axis.drop(labels, errors=errors)
2563 dropped = self.reindex(**{axis_name: new_axis})
2564 try:
C:\ProgramData\Anaconda3\lib\site-packages\pandas\core\indexes\base.py in drop(self, labels, errors)
3742 if errors != 'ignore':
3743 raise ValueError('labels %s not contained in axis' %
-> 3744 labels[mask])
3745 indexer = indexer[~mask]
3746 return self.delete(indexer)
ValueError: labels ['2018-06-01'] not contained in axis
#indexの確認
df.index()
エラー
TypeError Traceback (most recent call last)
<ipython-input-16-79c83efb9910> in <module>()
----> 1 df.index()
TypeError: 'DatetimeIndex' object is not callable
回答2件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2018/07/08 03:25