Search
 
SCRIPT & CODE EXAMPLE
 

PYTHON

Python pandas first and last element of column

>>> df['date'][df.index[0]]
10
>>> df['date'][df.index[-1]]
58
Comment

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')

Comment

PREVIOUS NEXT
Code Example
Python :: tensorflow to numpy 
Python :: how to create superuser in django heroku 
Python :: change a cell in pandas dataframe 
Python :: pd df sample 
Python :: how to make python open an application on mac 
Python :: install older version of python 
Python :: selenium chrome options suppress warnings python 
Python :: depth first search python 
Python :: mse python 
Python :: all select first value in column list pandas 
Python :: Week of the year Pandas 
Python :: how to check all the elements in a list are even or not 
Python :: heroku requirements.txt python 
Python :: python function vs lambda 
Python :: get random number positive or negative python 
Python :: add new row to dataframe pandas 
Python :: how to insert item at specifc index python 
Python :: qt designer messagebox python 
Python :: how to take first digit of number python 
Python :: initialize a 2d list python 
Python :: python finally keyword 
Python :: media pipe install ERROR: Could not find a version that satisfies the requirement mediapipe (from versions: none) 
Python :: at=error code=h10 desc= app crashed python flask 
Python :: Code of recursive binary search 
Python :: python reading and writing files 
Python :: tkinter text editor 
Python :: docker mount volume 
Python :: pd.datafram 
Python :: float to int in python 
Python :: fibonacci number 
ADD CONTENT
Topic
Content
Source link
Name
2+6 =