Tools

How to read CSV file in Python

December 24, 2017
Python, Tools

TLDR; Using pandas (pip install pandas) import pandas as pd data = pd.read_csv("actors.csv").to_dict(orient="row") Using native csv.DictReader import csv with open("actors.csv") as f: data = [r for r in csv.DictReader(f)] Reading as a List Let’s say we have the following CSV file, named actors.csv. You can download this file here. The first method demonstrated in Python docs would read the file as follows: Open the file Create a CSV reader Skip first line (header) For every line (row) in the file, do something import csv with open("actors. ...

MySQL Pretty Print in Command Line

April 23, 2014
Tools

TLDR; Use \G at the end of your query, as in mysql> SELECT * FROM sometable\G; Using pager I was looking for a better way to output mysql tables in console, and came across the following gem: mysql> pager less -SFX<br /> mysql> SELECT * FROM sometable; So an ugly output like this: Was transformed into a nice looking output like this: Using \G Another option is to add \G at the end of your command. ...