pandas读写csv

读:

train = pd.read_csv("../data/train.csv", keep_default_na=True)
survived, pclass, sex, age, sibsp, parch, ticket, fare, cabin, embarked = train.Survived, train.Pclass, train.Sex, train.Age, train.SibSp, train.Parch, train.Ticket, train.Fare, train.Cabin, train.Embarked
也可以train['Survived']

写:

submiss = pd.read_csv("../data/gender_submission.csv", keep_default_na=True)
id = submiss.PassengerId;
y_y = np.reshape(y_y, [418, ]).T
id = id.T
c = np.array([id, y_y]).T
pd_data = pd.DataFrame(c, columns=['PassengerId', 'Survived'])
pd_data.to_csv("gender_submission_mac_" + '%d' % (epoch + 1) + ".csv")

发表评论

电子邮件地址不会被公开。