Skip to main content

Overview

pandas is a software library written for the Python programming language for data manipulation and analysis. In particular, it offers data structures and operations for manipulating numerical tables and time series. It is free software released under the three-clause BSD license

Installation​

python3 -m venv venv
pip install pandas

Usage​

Import library and foundation​

import pandas as pd
  • To read csv: df = pd.read_csv('data path')
  • Set max columns: pd.set_option('display.max_rows', 20)
  • Set max rows: pd.set_option('display.max_columns', 20)
  • Rows x Columns: df.shape
  • Get info: df.info()
  • Get n head lines: df.head(n)
  • Get n tail lines: df.tail(n)
  • Write to csv: df.to_csv("filename.csv")
  • To read value of a column nationality: df.nationality.iloc[0]
  • To read first row: df.iloc[0]
  • To read first 10 rows of column (iloc row-first, column-second) nationality: df.loc[:10, 'nationality']
  • To read at specific rows: df.iloc[[1,2,5,8]]
  • To return a Series with the index of the maximum value for each column: df.idxmax()

DataFrame & Series​

  • Series: 1D labeled array
  • DataFrame: 2D labeled tabular structure