Python Forum
Need help understanding simple Array code. Please.
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Need help understanding simple Array code. Please.
#1
import pandas
import numpy
dataframe = pandas.read_csv("C:\Users\stluwa\cars.csv")
array = dataframe.values
X = array[:,0:8]
Y = array[:,8]
My problem is, I can not seem to figure out what is happening in the lines:
X = array[:,0:8]
Y = array[:,8]
My biggest question is what the [:,0:8] means. I'm doing some feature selection stuff, but i never learned python.
Reply
#2
(Apr-13-2019, 05:38 PM)stluwa Wrote:
import pandas
import numpy
dataframe = pandas.read_csv("C:\Users\stluwa\cars.csv")
array = dataframe.values
X = array[:,0:8]
Y = array[:,8]
My problem is, I can not seem to figure out what is happening in the lines:
X = array[:,0:8]
Y = array[:,8]
My biggest question is what the [:,0:8] means. I'm doing some feature selection stuff, but i never learned python.

Hey, I'm not sure why it's [:,0:8] or [:,8] but it should instead be [:0:8] and [:8] respectively.

These are slices. You can read more about them here.

https://docs.python.org/3/tutorial/intro...ml#strings
https://docs.python.org/3/tutorial/intro...html#lists
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Help with simple code JacobSkinner 1 325 Mar-18-2024, 08:08 PM
Last Post: deanhystad
  I have a code which is very simple but still I cannot detect what's wrong with it max22 1 484 Nov-07-2023, 04:32 PM
Last Post: snippsat
  Code understanding: Need help in understanding dictionary code jt123 0 470 Jul-09-2023, 01:13 PM
Last Post: jt123
  New to python/coding Need help on Understanding why this code isn't working. Thanks! mat3372 8 1,747 May-09-2023, 08:47 AM
Last Post: buran
  help me simple code result min and max number abrahimusmaximus 2 906 Nov-12-2022, 07:52 AM
Last Post: buran
  Simple encoding code ebolisa 3 1,445 Jun-18-2022, 10:59 AM
Last Post: deanhystad
  How would you (as an python expert) make this code more efficient/simple coder_sw99 3 1,804 Feb-21-2022, 10:52 AM
Last Post: Gribouillis
  Understanding a piece of code Michael1 4 1,407 Jan-20-2022, 07:14 PM
Last Post: Michael1
  Simple code question about lambda and tuples JasPyt 7 3,321 Oct-04-2021, 05:18 PM
Last Post: snippsat
  My simple code don't works !! Nabi666 1 1,604 Sep-06-2021, 12:10 PM
Last Post: jefsummers

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020