CSV Files Intro to Computer Science CS1510 Dr. Sarah Diesburg.

Slides:



Advertisements
Similar presentations
Introduction to C Programming
Advertisements

Files Introduction to Computing Science and Programming I.
 2007 Pearson Education, Inc. All rights reserved Introduction to C Programming.
Introduction to C Programming
1 CSC 1401 S1 Computer Programming I Hamid Harroud School of Science and Engineering, Akhawayn University
Introduction to Array The fundamental unit of data in any MATLAB program is the array. 1. An array is a collection of data values organized into rows and.
CS 0008 Day 2 1. Today Hardware and Software How computers store data How a program works Operators, types, input Print function Running the debugger.
CS190/295 Programming in Python for Life Sciences: Lecture 1 Instructor: Xiaohui Xie University of California, Irvine.
Chapter 14 Files and Exceptions II. "The Practice of Computing Using Python", Punch & Enbody, Copyright © 2013 Pearson Education, Inc. What we already.
Miscellaneous Excel Combining Excel and Access. – Importing, exporting and linking Parsing and manipulating data. 1.
Subroutines and Files Bioinformatics Ellen Walker Hiram College.
Chapter 17 Creating a Database.
CMPS 1371 Introduction to Computing for Engineers FILE Input / Output.
Lecture 2: Introduction to C Programming. OBJECTIVES In this lecture you will learn:  To use simple input and output statements.  The fundamental data.
EXCEL Intro to Microsoft Excel. Objectives for the Week Content ObjectivesLanguage Objectives I can create and manipulate charts, graphs, and reports.
An Introduction to Programming with C++ Sixth Edition Chapter 14 Sequential Access Files.
Using Text Files in Excel File I/O Methods. Working With Text Files A file can be accessed in any of three ways: –Sequential access: By far the most common.
Chapter 5 Files and Exceptions I. "The Practice of Computing Using Python", Punch & Enbody, Copyright © 2013 Pearson Education, Inc. What is a file? A.
Files Tutor: You will need ….
Chapter 13.3: Databases Invitation to Computer Science, Java Version, Second Edition.
1 CSE 2337 Chapter 7 Organizing Data. 2 Overview Import unstructured data Concatenation Parse Create Excel Lists.
Introduction to Files Intro to Computer Science CS1510, Section 2 Dr. Sarah Diesburg 1.
GCSE ICT Data Transfer. Data transfer Users often need to transfer data between software packages or computers. Until relatively recently this was difficult.
Chapter 14: Sequential Access Files
GCSE ICT Data Transfer.
Spreadsheets.
Fundamentals of Python: First Programs
Lecture 5 Text File I/O; Parsing.
Miscellaneous Excel Combining Excel and Access.
CSC201: Computer Programming
Creates the file on disk and opens it for writing
Introduction to Computing Science and Programming I
Intro to Computer Science CS1510 Dr. Sarah Diesburg
Chapter 8 Namespaces and Memory Realities
CS190/295 Programming in Python for Life Sciences: Lecture 1
Intro to Computer Science CS1510 Dr. Sarah Diesburg
Introduction to Strings
Seek Method and CSV Files
Java for Teachers Intermediate
C Programming Lecture-15 File I/O
String Encodings and Penny Math
File IO and Strings CIS 40 – Introduction to Programming in Python
Intro to Computer Science CS1510 Dr. Sarah Diesburg
files Dr. Bhargavi Goswami Department of Computer Science
Creates the file on disk and opens it for writing
Intro to Computer Science CS1510 Dr. Sarah Diesburg
Chapter 8 Namespaces and Memory Realities
Seek Method and CSV Files
Intro to Computer Science CS1510 Dr. Sarah Diesburg
Intro to Computer Science CS1510 Dr. Sarah Diesburg
funCTIONs and Data Import/Export
Files Handling In today’s lesson we will look at:
Introduction to Strings
Intro to Computer Science CS1510 Dr. Sarah Diesburg
Intro to Computer Science CS1510 Dr. Sarah Diesburg
Topics Introduction to File Input and Output
Intro to Computer Science CS1510 Dr. Sarah Diesburg
Intro to Computer Science CS1510 Dr. Sarah Diesburg
Chapter 8 Namespaces and Memory Realities
Intro to Computer Science CS1510 Dr. Sarah Diesburg
Introduction to Strings
Intro to Computer Science CS1510 Dr. Sarah Diesburg
String Encodings and Penny Math
Intro to Computer Science CS1510 Dr. Sarah Diesburg
Nate Brunelle Today: Web Reading
Intro to Computer Science CS1510 Dr. Sarah Diesburg
Intro to Computer Science CS1510 Dr. Sarah Diesburg
How to read from a file read, readline, reader
Introduction to Computer Science
CS313T Advanced Programming language
Presentation transcript:

CSV Files Intro to Computer Science CS1510 Dr. Sarah Diesburg

What is a File? A file is a collection of data that is stored on secondary storage like a disk or a thumb drive. Accessing a file means establishing a connection between the file and the program and moving data between the two.

Two Types of Files Files come in two general types:  Text files: files where control characters such as “\n” are translated. These are generally human readable  Binary files: all the information is taken directly without translation. Not readable and contains non-readable info.

Making and using a File Object fileObject = open(“myFile.txt”, “r”)  Opens the file “myFile.txt” in read-only mode fileObject.read()  Reads the entire contents of the file as a string and returns it. fileObject.readline()  Delivers the next line as a string.

Making and using a File Object fileObject.readLines()  Returns a single list of all the lines from the file. for line in fileObject:  Iterator to go through the lines of a file. fileObject.write(s)  writes the string s to the file fileObject.writelines(list)  write a list of strings (one at a time) to the file

Making and using a File Object fileObject.close()  When done, you close the file.

Spreadsheets The spreadsheet is a very popular, and powerful, application for manipulating data. Its popularity means there are many companies that provide their own version of the spreadsheet. It would be nice if those different versions could share their data…

CSV, Basic Sharing A basic approach to share data is the comma separated value (CSV) format:  it is a text format, accessible to all apps  each line (even if blank) is a row  in each row, each value is separated from the others by a comma (even if it is blank)  cannot capture complex things like formula

Athlete and BMI Example Demo (see athletes_data.csv and bmi2.py files) 9

Using the split() function for athlete in fin: last,first,height,weight,country,gender,sport=athlete.split(",") Split will split up the line by the argument (in this example, it is a comma Split will save the first string value into the first variable on the left side of the comma  E.g. first string gets saved in variable “last”, second gets saved in variable “height” Each line must have the exact same number of variables 10