top of page
learn_data_science.jpg

Data Scientist Program

 

Free Online Data Science Training for Complete Beginners.
 


No prior coding knowledge required!

Importing Data in Python.


What is Data Importation in Python?

Importing data in python is the use of various modules in python to transform different types of file formats into a python readability and interpretation format.

Before you start working with a set of data in python, you'll need to import it first. These data may be in different file formats which means each format's importation may differ from the other. In this article, you will learn about how to import:

- Flat files (eg. text file, excel files and csv files)

- Web files

- SQL Database


Importing Flat Files.

Text files - To import a text file into python, you will have first have to import the pandas library(as its alias). This will give you access to use all related functions in the library. Importing a text file using pandas will read the file into a DataFrame object.

import pandas as pd
pd.read_table("filelocation/filename.txt")

Excel files - Importing an excel file will require you to import python's pandas library. This will give you access to use all related functions in the library. Note that excel files have various file extensions.

import pandas as pd
pd.read_excel("filename.xlsx")

CSV files - To import a comma-separated file into python, you will have first have to import the pandas library(as its alias). This will give you access to use all related functions in the library. Importing a CSV file using pandas will read the file into a DataFrame object. Note that the file extension should be .csv

import pandas as pd 
pd.read_csv("filename.csv")

Importing Web files.

Getting data from a website is mainly done using the python library requests, urllib, and urlretrieve.

import requests as req
url = "url.of.website"
req.get(url, allow_redirects = True)

Importing SQL Database.

The required python package to import from SQL Database is pyodbc. Once you import the module, you will need to establish a connection with the database to be able to import or extract the data you need.

import pyodbc
sql_connection = pyodbc.connect("sqlserverpathway")
pd.read_sql_query('type your sql query here', sql_connection)

 
 
 

Comments


COURSES, PROGRAMS & CERTIFICATIONS

 

Advanced Business Analytics Specialization

Applied Data Science with Python (University of Michigan)

Data Analyst Professional Certificate (IBM)

Data Science Professional Certificate (IBM)

Data Science Specialization (John Hopkins University)

Data Science with Python Certification Training 

Data Scientist Career Path

Data Scientist Nano Degree Program

Data Scientist Program

Deep Learning Specialization

Machine Learning Course (Andrew Ng @ Stanford)

Machine Learning, Data Science and Deep Learning

Machine Learning Specialization (University of Washington)

Master Python for Data Science

Mathematics for Machine Learning (Imperial College London)

Programming with Python

Python for Everybody Specialization (University of Michigan)

Python Machine Learning Certification Training

Reinforcement Learning Specialization (University of Alberta)

Join our mailing list

Data Insight participates in affiliate programs and may sometimes get a commission through purchases made through our links without any additional cost to our visitors.

bottom of page