AssertionError class numpy ndarray

0 votes

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'>
Dec 2, 2020 in Python by Joy
• 120 points
4,503 views

1 answer to this question.

0 votes
Same problem here bro!
answered Dec 8, 2020 by Bijoy

Hi@Bijoy,

You need to follow the format of your dataset. In the dataset check the date column. In that, no hyphen is there. But at the time of extracting data, you are feeding hyphens.

dataset['2020-07-06']

So, just use the exact format that you have in your dataset. If it is in a string, then use the string at the time of data extraction.

Related Questions In Python

0 votes
1 answer

AssertionError: <class 'numpy.ndarray'>

Hi, @There, The traceback module and sys.exc_info are ...READ MORE

answered Oct 19, 2020 in Python by anonymous
• 65,770 points
1,941 views
0 votes
1 answer

AttributeError: type object 'numpy.ndarray' has no attribute '__array_function__'

Hi@akhtar, I think numpy version is not compatible ...READ MORE

answered Apr 13, 2020 in Python by MD
• 95,460 points
14,803 views
0 votes
3 answers

AttributeError: 'numpy.ndarray' object has no attribute 'append'

for root, dirs, files in os.walk(directory): ...READ MORE

answered Dec 12, 2020 in Python by Rajiv
• 8,870 points
53,018 views
+1 vote
1 answer

'numpy.ndarray' object has no attribute 'append'

Hi@Noman, You created two empty list. And in ...READ MORE

answered May 17, 2020 in Python by MD
• 95,460 points
8,229 views
+1 vote
1 answer

AttributeError: 'numpy.ndarray' object has no attribute 'append'

Hi, You created two empty list. And in ...READ MORE

answered May 17, 2020 in Python by MD
• 95,460 points
5,565 views
0 votes
1 answer

AttributeError: 'numpy.ndarray' object has no attribute 'append'

Hi@Nilesh, You created two empty lists. And in ...READ MORE

answered Aug 11, 2020 in Python by MD
• 95,460 points
3,291 views
0 votes
1 answer

AttributeError: 'numpy.ndarray' object has no attribute 'append'

Hi@Nilesh, You have created two empty lists. And ...READ MORE

answered Aug 11, 2020 in Python by MD
• 95,460 points
6,434 views
+1 vote
2 answers

View onto a numpy array?

 just index it as you normally would. ...READ MORE

answered Oct 18, 2018 in Python by roberto
1,072 views
0 votes
1 answer

Python class inherits an object

Python 3.x: class MyClass(object): = new-style class class MyClass: ...READ MORE

answered Apr 17, 2018 in Python by anonymous
1,923 views
webinar REGISTER FOR FREE WEBINAR X
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP