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
  Simple code not working properly tmv 2 557 Feb-28-2025, 09:27 PM
Last Post: deanhystad
  python code to calculate mean of an array of numbers using numpy viren 3 1,252 May-29-2024, 04:49 PM
Last Post: Gribouillis
  Help with simple code JacobSkinner 1 1,389 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 1,301 Nov-07-2023, 04:32 PM
Last Post: snippsat
  Code understanding: Need help in understanding dictionary code jt123 0 961 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 3,587 May-09-2023, 08:47 AM
Last Post: buran
  help me simple code result min and max number abrahimusmaximus 2 1,723 Nov-12-2022, 07:52 AM
Last Post: buran
  Simple encoding code ebolisa 3 2,371 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 2,623 Feb-21-2022, 10:52 AM
Last Post: Gribouillis
  Understanding a piece of code Michael1 4 2,423 Jan-20-2022, 07:14 PM
Last Post: Michael1

Forum Jump:

User Panel Messages

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