Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR PYTHON

How to get the first and last values from the dataframe column using a function

df['column_name'].iloc[0] # first element 
df['column_name'].iloc[-1] # last element
#OR
df.column_name.head(1)
df.column_name.tail(1)
#OR if the column_one is sorted using sort_values(column_one)
df.nlargest(1, 'column_one')
df.nsmallest(1, 'column_one')

Source by stackoverflow.com #
 
PREVIOUS NEXT
Tagged: #How #values #dataframe #column #function
ADD COMMENT
Topic
Name
5+9 =