Last active
August 29, 2015 14:11
-
-
Save blink1073/b15f6f99f6e8d2e7c151 to your computer and use it in GitHub Desktop.
Read CSV to Numpy Record using Pandas Read_CSV
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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