Skip to content

Instantly share code, notes, and snippets.

@blink1073
Last active August 29, 2015 14:11
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save blink1073/b15f6f99f6e8d2e7c151 to your computer and use it in GitHub Desktop.
Save blink1073/b15f6f99f6e8d2e7c151 to your computer and use it in GitHub Desktop.
Read CSV to Numpy Record using Pandas Read_CSV
import pandas as pd
import numpy as np
def read_csv(fname, **kwargs):
df = pd.read_csv(fname, **kwargs)
arrs = [df.icol(i).data for i in range(df.shape[1])]
dtype = [(h, df.dtypes[h]) for h in df.columns]
arr = np.rec.fromarrays(arrs, dtype=dtype)
arr.columns = df.columns.tolist()
return arr
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment