Index and Columns

import pandas as pd 

url = "https://raw.githubusercontent.com/fahadsultan/csc272/main/data/elections.csv"

elections = pd.read_csv(url)

.columns

The .columns attribute returns the column labels of the DataFrame. It is a pandas Index object.

elections.head()
Year Candidate Party Popular vote Result %
0 1824 Andrew Jackson Democratic-Republican 151271 loss 57.210122
1 1824 John Quincy Adams Democratic-Republican 113142 win 42.789878
2 1828 Andrew Jackson Democratic 642806 win 56.203927
3 1828 John Quincy Adams National Republican 500897 loss 43.796073
4 1832 Andrew Jackson Democratic 702735 win 54.574789
elections.columns
Index(['Year', 'Candidate', 'Party', 'Popular vote', 'Result', '%'], dtype='object')
type(elections.columns)
pandas.core.indexes.base.Index

.index

.index attribute returns the row labels of the DataFrame. It is also a pandas Index object.

elections.index
RangeIndex(start=0, stop=182, step=1)
type(elections.index)
pandas.core.indexes.range.RangeIndex