Data Analysis with Python

A common task for scientists and engineers is to analyze data from an external source that may be in a text or comma separated value (CSV) format.

By importing the data into Python, data analysis such as statistics, trending, or calculations can be made to synthesize the information into relevant and actionable information. Tutorials below demonstrate how to import data (including online data), perform a basic analysis, trend the results, and export the results to another text file. Two examples are provided with Pandas and Numpy.

Import and Export Data (Jupyter Notebook)
Import and Export Data (Google Colab)

Pandas Import and Export Data

import pandas as pd
url = 'http://apmonitor.com/pdc/uploads/Main/tclab_data2.txt'
data = pd.read_csv(url)
data.to_csv('file.csv')

Numpy Import and Export Data

import numpy as np
data = np.loadtxt('file.csv',delimiter=',',skiprows=1)
np.savetxt('file2.csv',data,delimiter=',',\
           comments='',header='Index,Time,Q1,Q2,T1,T2')

Additional script files with Python source code with sample data are below.


Import Data and Analyze with Numpy

Python Data Analysis Example Source Code (Numpy)


Import Data and Analyze with Pandas

Data File with Headers
Python Data Analysis Example Source Code (Pandas)


Import Online Data and Analyze

Below is an example of pulling data from an Internet source, such as financial information about a stock. The example shows how to request, parse, and display the financial data.

Google Stock Data File

Once the data is imported, it can be analyzed with many different tools such as machine learning algorithms. Below is an example of using the data for analysis of correlation between open and close price of Google publicly traded shares.


This tutorial can also be completed with Excel and Matlab. Click on the appropriate link for additional information.

Home | Data Analysis with Python
Streaming Chatbot
💬