[Self-use] pandas read CSV file

import numpy as np
import pandas as pd
import csv


def load_csv(filename, target_dtype, features_dtype, target_column=-1):
    """Load dataset from CSV file with a header row."""
    pd_csv = pd.read_csv(filename)
    data_file = pd_csv.values
    data = data_file[:, 1:-1].astype(features_dtype)
    target = data_file[:, target_column].astype(target_dtype)

    return data, target


transfer:

training_data, training_target = load_csv(train_file, target_dtype=np.int, eatures_dtype=np.float32)

 

    PS: For personal use without explanation Author: A handsome pot    

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=324376923&siteId=291194637