Avatar of Simon Leung
Simon Leung
 asked on

Python code query

1. What does .values[:,0] represent in the following code :

print(Using Column Data Type::" )
print(df.select_dtypes(include=['float64']).values[:,0] )

2. What does [0,24,51] represent :

print(Excluding Specific Row indices::" )
print(df.drop([0,24,51], axis=0).head())
Python

Avatar of undefined
Last Comment
Louis LIETAER

8/22/2022 - Mon
Louis LIETAER

1. What does .values[:,0] represent in the following code :

Values representing a numpy array with values of pandas data frame.

[:,0] is the first column of the numpy Array.
Louis LIETAER

2. What does [0,24,51] represent ?

For pandas dataframe df.drop([0,24,51], suppress lines 0,24,51

example
>>> df.drop([0, 1])
   A  B   C   D
2  8  9  10  11

Open in new window

pepr

It does not come from plain Python. Python knows slicing; however, that one is related to NumPy where slicing can be more complex. I am not good at NumPy, so take the following as starting point

https://numpy.org/doc/1.18/user/basics.indexing.html?highlight=slice
I started with Experts Exchange in 2004 and it's been a mainstay of my professional computing life since. It helped me launch a career as a programmer / Oracle data analyst
William Peck
ASKER CERTIFIED SOLUTION
Louis LIETAER

THIS SOLUTION ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
GET A PERSONALIZED SOLUTION
Ask your own question & get feedback from real experts
Find out why thousands trust the EE community with their toughest problems.