{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "# CSV (Comma Seperated Values)\n", "The so called CSV (Comma Separated Values) format is the most common import and export\n", "format for spreadsheets and databases. There is no âCSV standardâ, so the format is\n", "operationally defined by the many applications which read and write it. The lack of a standard\n", "means that subtle differences often exist in the data produced and consumed by different\n", "applications. These differences can make it annoying to process CSV files from multiple\n", "sources. Still, while the delimiters and quoting characters vary, the overall format is similar\n", "enough that it is possible to write a single module which can efficiently manipulate such data,\n", "hiding the details of reading and writing the data from the programmer." ] }, { "cell_type": "code", "execution_count": 2, "metadata": { "collapsed": true }, "outputs": [], "source": [ "#importing the python inbuilt csv module\n", "import csv" ] }, { "cell_type": "code", "execution_count": 4, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "['Games', 'Sports', 'Men', 'Women', 'Total M+W', 'Gold', 'Silver', 'Bronze', 'Total']\n", "['1900', '1', '1', '0', '1', '0', '2', '0', '2']\n", "['1920', '2', '6', '0', '6', '0', '0', '0', '0']\n", "['1924', '2', '13', '2', '15', '0', '0', '0', '0']\n", "['1928', '2', '21', '0', '21', '1', '0', '0', '1']\n", "['1932', '3', '30', '0', '30', '1', '0', '0', '1']\n", "['1936', '4', '27', '0', '27', '1', '0', '0', '1']\n", "['1948', '10', '79', '0', '79', '1', '0', '0', '1']\n", "['1952', '11', '60', '4', '64', '1', '0', '1', '2']\n", "['1956', '8', '58', '1', '59', '1', '0', '0', '1']\n", "['1960', '6', '45', '0', '45', '0', '1', '0', '1']\n", "['1964', '8', '52', '1', '53', '1', '0', '0', '1']\n", "['1968', '5', '25', '0', '25', '0', '0', '1', '1']\n", "['1972', '7', '40', '1', '41', '0', '0', '1', '1']\n", "['1976', '2', '20', '0', '20', '0', '0', '0', '0']\n", "['1980', '1', '58', '18', '76', '1', '0', '0', '1']\n", "['1984', '0', '0', '0', '48', '0', '0', '0', '0']\n", "['1988', '7', '0', '0', '46', '0', '0', '0', '0']\n", "['1992', '5', '0', '0', '53', '0', '0', '0', '0']\n", "['1996', '13', '44', '4', '49', '0', '0', '1', '1']\n", "['2000', '7', '0', '0', '65', '0', '0', '1', '1']\n", "['2004', '14', '48', '25', '73', '0', '1', '0', '1']\n", "['2008', '12', '31', '25', '56', '1', '0', '2', '3']\n", "['2012', '13', '60', '23', '83', '0', '2', '4', '6']\n", "['2016', '15', '66', '54', '118', '0', '1', '1', '2']\n" ] } ], "source": [ "#opening csv file in reading mode to print rows\n", "with open('data.csv','r') as csvfile:\n", " # iterator is object\n", " iterator = csv.reader(csvfile, delimiter=',')\n", " for each_row in iterator:\n", " print(each_row)" ] }, { "cell_type": "code", "execution_count": 7, "metadata": {}, "outputs": [], "source": [ "with open('data.csv','r') as csvfile:\n", " # iterator is object\n", " iterator = csv.reader(csvfile, delimiter=',')" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "collapsed": true }, "outputs": [], "source": [] } ], "metadata": { "kernelspec": { "display_name": "Python 3", "language": "python", "name": "python3" }, "language_info": { "codemirror_mode": { "name": "ipython", "version": 3 }, "file_extension": ".py", "mimetype": "text/x-python", "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", "version": "3.6.1" } }, "nbformat": 4, "nbformat_minor": 2 }