How to import a CSV file in Python?
MACHINE LEARNING RECIPES

How to import a CSV file in Python?

How to import a CSV file in Python?

This recipe helps you import a CSV file in Python

0
In [1]:
## How to import a CSV file in Python
def Snippet_171():
    print()
    print(format('How to import a CSV file in Python','*^82'))

    import warnings
    warnings.filterwarnings("ignore")

    # load libraries
    import csv
    import numpy
    import pandas

    # Load CSV (using python)
    filename = 'pima.indians.diabetes.data.csv'
    raw_data = open(filename, 'rt')
    reader = csv.reader(raw_data, delimiter=',', quoting=csv.QUOTE_NONE)
    x = list(reader)
    data = numpy.array(x).astype('float')
    print(data.shape)

    # Load CSV (using numpy)
    filename = 'pima.indians.diabetes.data.csv'
    raw_data = open(filename, 'rt')
    data = numpy.loadtxt(raw_data, delimiter=",")
    print(data.shape)

    # Load CSV (using Pandas)
    filename = 'pima.indians.diabetes.data.csv'
    names = ['preg', 'plas', 'pres', 'skin', 'test',
             'mass', 'pedi', 'age', 'class']
    data = pandas.read_csv(filename, names=names)
    print(data.shape)

Snippet_171()
************************How to import a CSV file in Python************************
(768, 9)
(768, 9)
(768, 9)

Relevant Projects

German Credit Dataset Analysis to Classify Loan Applications
In this data science project, you will work with German credit dataset using classification techniques like Decision Tree, Neural Networks etc to classify loan applications using R.

Predict Employee Computer Access Needs in Python
Data Science Project in Python- Given his or her job role, predict employee access needs using amazon employee database.

Zillow’s Home Value Prediction (Zestimate)
Data Science Project in R -Build a machine learning algorithm to predict the future sale prices of homes.

Data Science Project-All State Insurance Claims Severity Prediction
Data science project in R to develop automated methods for predicting the cost and severity of insurance claims.

Human Activity Recognition Using Smartphones Data Set
In this deep learning project, you will build a classification system where to precisely identify human fitness activities.

Perform Time series modelling using Facebook Prophet
In this project, we are going to talk about Time Series Forecasting to predict the electricity requirement for a particular house using Prophet.

Learn to prepare data for your next machine learning project
Text data requires special preparation before you can start using it for any machine learning project.In this ML project, you will learn about applying Machine Learning models to create classifiers and learn how to make sense of textual data.

Data Science Project on Wine Quality Prediction in R
In this R data science project, we will explore wine dataset to assess red wine quality. The objective of this data science project is to explore which chemical properties will influence the quality of red wines.

Ecommerce product reviews - Pairwise ranking and sentiment analysis
This project analyzes a dataset containing ecommerce product reviews. The goal is to use machine learning models to perform sentiment analysis on product reviews and rank them based on relevance. Reviews play a key role in product recommendation systems.

Choosing the right Time Series Forecasting Methods
There are different time series forecasting methods to forecast stock price, demand etc. In this machine learning project, you will learn to determine which forecasting method to be used when and how to apply with time series forecasting example.