Skip to content

Instantly share code, notes, and snippets.

@xccds
Created October 10, 2014 06:49
Show Gist options
  • Save xccds/791a100189486459d478 to your computer and use it in GitHub Desktop.
Save xccds/791a100189486459d478 to your computer and use it in GitHub Desktop.
#原始的方式
lines = [line.split(',') for line in open('iris.csv')]
df = [[float(x) for x in line[:4]] for line in lines[1:]]
#使用numpy包
import numpy as np
lines = np.loadtxt('iris.csv',delimiter=',',dtype='str')
df = lines[1:,:4].astype('float')
#使用pandas包
import pandas as pd
df = pd.read_csv('iris.csv')
df=df.ix[:,:4]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment