I am having Time Series data in my data frame (dataset) after indexing by date when I am trying to call any value by date am getting an error of
AssertionError: <class 'numpy.ndarray'> please help me.
Please follow below for code:
# Import libraries
import pandas as pd
import numpy as np
import matplotlib.pyplot as plt
import math
%matplotlib nbagg
# Upload Dataset
dataset = pd.read_csv("Data.csv")
dataset.head()
Ticker Per Date Time Open High Low Close Volume
0 1.HK 5 20200706 33000 52.00 52.55 51.80 52.20 739591
1 1.HK 5 20200706 33500 52.20 52.55 52.15 52.55 216500
2 1.HK 5 20200706 34000 52.55 52.85 52.50 52.80 430000
3 1.HK 5 20200706 34500 52.80 52.95 52.75 52.90 316925
4 1.HK 5 20200706 35000 52.90 53.05 52.85 53.00 473288
# Adding New Column with Date and time
dataset['Datetime'] = dataset['Date'].astype(str) + ' ' + dataset['Time'].astype(str)
# Changing datetime column format into datetime Format
dataset['Datetime'] = pd.to_datetime(dataset['Datetime'],format='%Y%m%d %M%f')
dataset['Date'] = pd.to_datetime(dataset['Date'],format='%Y%m%d')
dataset['Time'] = pd.to_datetime(dataset['Time'],format= '%M%f')
# setting the index
dataset.set_index("Datetime",inplace = True)
dataset['2020-07-06']
---------------------------------------------------------------------------
AssertionError Traceback (most recent call last)
<ipython-input-8-9132c41bc610> in <module>
----> 1 dataset['2020-07-06']
~\anaconda3\lib\site-packages\pandas\core\frame.py in __getitem__(self, key)
2883 # either we have a slice or we have a string that can be converted
2884 # to a slice for partial-string date indexing
-> 2885 return self._slice(indexer, axis=0)
2886
2887 # Do we have a (boolean) DataFrame?
~\anaconda3\lib\site-packages\pandas\core\generic.py in _slice(self, slobj, axis)
3555 Slicing with this method is *always* positional.
3556 """
-> 3557 assert isinstance(slobj, slice), type(slobj)
3558 axis = self._get_block_manager_axis(axis)
3559 result = self._constructor(self._mgr.get_slice(slobj, axis=axis))
AssertionError: <class 'numpy.ndarray'>