CodeNotes

Python in Data Science

(Note: This is a work in progress and new information is being added.)

Input / Output

  • Open, read and write .csv or .txt file
  • Pandas: Read and write .csv or txt file into a DataFrame
  • Write output to a .txt file in a for loop

Install

  • Install library or module using pip
  • Check version of installed library

Basics

Mathematical and Aggregate Functions

  • Numpy: Arithmetic functions
  • Numpy: Aggregate functions: row-wise and column-wise
  • Pandas: Aggregate function: row-wise and column-wise
  • Pandas: Calculate cumulative sum and mean for a Series or DataFrame
  • Pandas: Calculate rolling sum and mean for a Series or DataFrame

Date and Time

  • Pandas: Create a timestamp
  • Pandas: Create a date range
  • Pandas: Create a date range of fixed frequency
  • Pandas: Create a date range of random frequency
  • Pandas: Create random dates
  • Pandas: Add or subtract year, month, day, hour, minute, second from a timestamp
  • Pandas: Convert string to a timestamp
  • Pandas: Convert naive time to aware time i.e. add timezone to a timestamp
  • Pandas: Resample time series
  • Pandas: Group by using time series
  • Pandas: Calculate difference between two timestamps
  • Pandas: Shift or lead or lag time series

Data Visualization