Python Mini-Course University of Oklahoma Department of Psychology Lesson 18 Using text files to share data with other programs 5/07/09 Python Mini-Course:

Slides:



Advertisements
Similar presentations
Someone hands you a a diskette that has data about schools in the City of Cleveland. They tell you that the school file is in a a dBase format. How do.
Advertisements

The SAS ® System Additional Information on Statistical Analysis Programming.
The INFILE Statement Reading files into SAS from an outside source: A Very Useful Tool!
Excel Objects, User Interface, and Data Entry. ◦ Application Window  Title Bar  Menu Bar  Toolbars  Status Bar  Worksheet Window  Worksheet Input.
Access - Project 1 l What Is a Database? –A Collection of Data –Organized in a manner to allow: »Access »Retrieval »Use of That Data.
Exploring Microsoft Excel 2002 Chapter 7 Chapter 7 List and Data Management: Converting Data to Information By Robert T. Grauer Maryann Barber Exploring.
 Cut and paste sometimes works  More likely want to go to temp sheet  Get it in any way you can  AND THEN clean it up.
Matlab DIY Lesson 1: Reading Data. Purpose of this Seminar Basic Ability to handle Data Analysis and Presentation in Matlab Understand how data is organized.
Designing a Database Unleashing the Power of Relational Database Design.
Chapter 7 Data Management. Agenda Database concept Import data Input and edit data Sort data Function Filter data Create range name Calculate subtotal.
2015/6/301 TransCAD Managing Data Tables. 2015/6/302 Create a New Table.
Fall 2006AE6382 Design Computing1 Matlab File & Directory Management Learning Objectives Define file input and output terminology Compare high and low.
CIVIL RIGHTS DATA COLLECTION Workshop April 9, 2015 The Civil Rights Data Collection (CRDC) is a mandatory data collection of the U.S. Department of Education’s.
Tutorial 8 Sharing, Integrating and Analyzing Data
SPSS 1: An Introduction to the Statistical Package SPSS Suzie Cro MRC Clinical Trials Unit.
Add a File with X, Y coordinates to MapWindow
Pasewark & Pasewark 1 Access Lesson 6 Integrating Access Microsoft Office 2007: Introductory.
Access Tutorial 8 Sharing, Integrating, and Analyzing Data
1 Access Lesson 6 Integrating Access Microsoft Office 2010 Introductory Pasewark & Pasewark.
Managing Your Own Data (…if you have to) Kathryn A. Carson, Sc.M. Senior Research Associate Department of Epidemiology Johns Hopkins Bloomberg School of.
Copyright © 2010 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Starting Out with Programming Logic & Design Second Edition by Tony Gaddis.
Python Mini-Course University of Oklahoma Department of Psychology Lesson 17 Reading and Writing Files 5/10/09 Python Mini-Course: Lesson 17 1.
© 2008 The McGraw-Hill Companies, Inc. All rights reserved. ACCESS 2007 M I C R O S O F T ® THE PROFESSIONAL APPROACH S E R I E S Lesson 4 – Creating New.
Python Mini-Course University of Oklahoma Department of Psychology Lesson 19 Handling Exceptions 6/09/09 Python Mini-Course: Lesson 19 1.
Importing existing reference lists Lorraine Beard & Martin Snelling DRAFT: May 2007.
Programming in R Getting data into R. Importing data into R In this session we will learn: Some basic R commands How to enter data directly into R How.
Copyright © 2008 Pearson Prentice Hall. All rights reserved. 1 Import Data From Text Files and Other Sources Importing is the process of inserting data.
Copyright © 2012 Pearson Education, Inc. Publishing as Pearson Addison-Wesley C H A P T E R 2 Input, Processing, and Output.
DATABASE DESIGN USING MICROSOFT ACCESS. What is a Database?  DMS Database management system  Database Collection of data organized in a manner that.
STREAMS AND FILES OVERVIEW.  Many programs are "data processing" applications  Read the input data  Perform sequence of operations on this data  Write.
DATABASE. Computer-based filing systems Information in computer-based filing systems are stored in DATA FILES. A FILE is a collection of RELATED RECORDS.
Python Mini-Course University of Oklahoma Department of Psychology Day 3 – Lesson 12 More about strings 05/02/09 Python Mini-Course: Day 3 – Lesson 12.
INSERT BOOK COVER 1Copyright © 2011 Pearson Education, Inc. Publishing as Prentice Hall. Exploring Microsoft Office Excel 2010 by Robert Grauer, Keith.
Advanced Word - Lesson 1: Sorting and Calculating.
Bringing Data into SAS From Menu: –File –Import Data –Spreadsheet example first Pick file by browsing Select Library and Member (we will talk about this.
DAY 4: MICROSOFT EXCEL: IN-CLASS PROJECT Aliya Farheen August 27, 2015.
10.11 Data Manipulation 1. Getting External Data.
Lesson 2 Topic - Reading in data Chapter 2 (Little SAS Book)
Python Mini-Course University of Oklahoma Department of Psychology Day 4 – Lesson 13 Case study: Word play 05/02/09 Python Mini-Course: Day 4 – Lesson.
R packages/libraries Data input/output Rachel Carroll Department of Public Health Sciences, MUSC Computing for Research I, Spring 2014.
Representing Characters in a computer Pressing a key on the computer a code is generated that the computer can convert into a symbol for displaying or.
Chapter 14: Files and Streams. 2Microsoft Visual C# 2012, Fifth Edition Files and the File and Directory Classes Temporary storage – Usually called computer.
Databases and Speadsheets
MySQL Importing and creating a database. CSV (Comma Separated Values) file CSV = Comma Separated Values – they are simple text files containing data which.
CHAPTER 17 INTRODUCTION TO SPREADSHEETS. SPREADSHEETS Application Software designed to aid users in entering, moving,copying, labeling, displaying and.
Files Tutor: You will need ….
W W W. W A T S O N W Y A T T. C O M Importing Survey Data.
Importing Data to Excel. Suppose you have a delimited* text file and you need to bring it into Excel. Follow these steps… *Delimited means text separated.
A table is a set of data elements (values) that is organized using a model of vertical columns (which are identified by their name) and horizontal rows.
Files in Python The Basics. Why use Files? Very small amounts of data – just hardcode them into the program A few pieces of data – ask the user to input.
Lesson 2 Topic - Reading in data Programs 1 and 2 in course notes –Chapter 2 (Little SAS Book)
1 Essential Computing for Bioinformatics Bienvenido Vélez UPR Mayaguez Lecture 3 High-level Programming with Python Part III: Files and Directories Reference:
Review: A Computational View Programming language common concepts: 1. sequence of instructions -> order of operations important 2. conditional structures.
Plain Text ASCII (American Standard Code for Information Interchange) - basic English alphabet character encoding UTF-8 (Universal Character Set Transformation.
Copyright 2007, Paradigm Publishing Inc. EXCEL 2007 Chapter 8 BACKNEXTEND 8-1 LINKS TO OBJECTIVES Import data from Access, a Web site, or a CSV text file.
Multi-Axis Tabular Loads in ANSYS Workbench
Topic: File Input/Output (I/O)
Interfacing with a database
Data Transfer ASCII FILES.
Prepare data for importing
CQG XData Walkthrough.
Access Lesson 14 Import and Export Data
Comma Separated Values
GIS Lecture: Data.
Fundamentals of Data Structures
Microsoft Excel 2007 – Level 2
How to save information in files open, write, close
funCTIONs and Data Import/Export
GIS Lecture: Data.
Retrieving numerical values.
Presentation transcript:

Python Mini-Course University of Oklahoma Department of Psychology Lesson 18 Using text files to share data with other programs 5/07/09 Python Mini-Course: Lesson 18 1

Lesson objectives 1. Identify and describe the common file formats for data exchange, including text files, csv files, and tab-delimited files. 2. Read and write delimited text files in Python 3. Use a spreadsheet to read and create delimited text files 5/07/09 Python Mini-Course: Lesson 18 2

Data exchange Key principle: Data must be stored in a common format Industry standard formats for encoding text ASCII, Unicode, etc. Industry standard formats for exchanging data Delimited text files 5/07/09 Python Mini-Course: Lesson 18 3

Delimiting Method of marking the boundaries between data fields in databases, spreadsheets, and tabular data 5/07/09 Python Mini-Course: Lesson 18 4

Common delimited text files White-space delimited Any non-printable character code (space, tab, newline, etc) Common in older systems and for numeric data (e.g. SAS data files) 5/07/09 Python Mini-Course: Lesson 18 5

Common delimited text files Comma delimited Most common format Files are designated as csv files (comma-separated values) Example: USF norms 5/07/09 Python Mini-Course: Lesson 18 6

Common delimited text files Tab delimited Excellent format for tabular data Can be read directly by Excel Sometimes called tsv files Example: Substance Abuse and Mental Health Data Archive 5/07/09 Python Mini-Course: Lesson 18 7

Example: sqrtable.py # Create a table of squares and square roots import math start, stop, step = 1, 100, 1 delimiter = '\t' filename = 'squares.txt' num, sqr, sqr_rt = [], [], [] for val in range(start, stop+1, step): num.append(val) sqr.append(val**2) sqr_rt.append(math.sqrt(val)) 5/07/09 Python Mini-Course: Lesson 18 8

Example: sqrtable.py # Save to a delimited text file fout = open(filename, 'w') hdr = 'Num%sSquare%sSqrRoot\n' % (delimiter, delimiter) print hdr fout.write(hdr) for row in zip(num, sqr, sqr_rt): line = '%d%s%d%s%2.4f\n' % \ (row[0], delimiter, row[1], delimiter, row[2]) print line fout.write(line) fout.close() 5/07/09 Python Mini-Course: Lesson 18 9

Exercises 1. Open the file square.txt with a text editor 2. Open the file square.txt with a spreadsheet application (e.g., Excel) 3. Create a similar spreadsheet and save as a text file 5/07/09 Python Mini-Course: Lesson 18 10

Example: readsqr.py delimiter = '\t' filename = 'squares.txt' num, sqr, sqr_rt = [], [], [] fin = open(filename, 'r') hdr = fin.readline().strip() for row in fin: line = row.strip() entries = line.split(delimiter) num.append(int(entries[0])) sqr.append(int(entries[1])) sqr_rt.append(float(entries[2])) fin.close() 5/07/09 Python Mini-Course: Lesson 18 11

Example: readsqr.py # Print a table of values print hdr for row in zip(num, sqr, sqr_rt): line = '%d%s%d%s%2.4f' % \ (row[0], delimiter, row[1], delimiter, row[2]) print line 5/07/09 Python Mini-Course: Lesson 18 12