0

I have Python 3.6.8 installed on my computer. I am performing data analysis on a public dataset. Pandas is correctly able to read the dataset but when I do slicing on the dataframe, I get TypeError: '(slice(None, None, None), slice(None, None, None))' is an invalid key. My code is as follows:

import pandas as pd

data = pd.read_csv('netflix_titles.csv')
data[:,:]

My computer specs are:

CPU: Intel i5-6200U

RAM: 12.0 GB

OS: Windows 10

OS build: 19042.746

System type: 64-bit operating system, x64-based processor

Someone help please!

tarora
  • 11
  • 4
  • 5
    No screenshots of code please. [Edit] your question with the code as text. – BigBen Feb 15 '21 at 15:42
  • 2
    [Discourage screenshots of code and/or errors](https://meta.stackoverflow.com/questions/303812/discourage-screenshots-of-code-and-or-errors)...[Why not upload images of code on SO when asking a question?](https://meta.stackoverflow.com/questions/285551/why-not-upload-images-of-code-on-so-when-asking-a-question) ... [You should not post code as an image because:...](https://meta.stackoverflow.com/a/285557/2823755) – wwii Feb 15 '21 at 15:43
  • 2
    Welcome to SO. Please take the [tour] and take the time to read [mre], [ask] and the other links found on that page. [How to make good reproducible pandas examples](https://stackoverflow.com/questions/20109391/how-to-make-good-reproducible-pandas-examples) – wwii Feb 15 '21 at 15:45
  • [https://pandas.pydata.org/docs/user_guide/index.html](https://pandas.pydata.org/docs/user_guide/index.html) ... [Copying data](https://pandas.pydata.org/docs/user_guide/basics.html#copying) – wwii Feb 15 '21 at 15:47

1 Answers1

0

You would need to properly utilise indexing, if you want to select relevant elements from your Pandas dataframe. For instance, you would be able to access the dataframe elements by using data.iloc[:,:], but you are doing it without using iloc or loc. You would always need to utilise iloc or loc for indexing Pandas dataframes, as conventional indexing done for e.g. arrays would not work here. If you wanted to select, say the first 10 rows and elements from the second column, you would do it with data.iloc[:10,1], given that indexing in Python starts from a 0. However, if you still wanted to access elements with data[:,:], you can convert your dataframe to a numpy array like this:

data = data.to_numpy()

Refer Pandas indexing techniques here https://pandas.pydata.org/pandas-docs/stable/user_guide/indexing.html.

JChat
  • 784
  • 2
  • 13
  • 33