0% found this document useful (0 votes)
31 views16 pages

Welcome To The Case Study!: Hugo Bowne-Anderson

This document discusses Python tools for data science, including using zip() to combine lists, defining functions, list comprehensions, generators for streaming data, and using pandas' read_csv iterator. The document provides examples of building generator functions and reading CSV files in chunks to work with large datasets. Finally, it encourages practicing the skills covered in working with functions, iterators, list comprehensions, and generators.

Uploaded by

vrhdzv
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
31 views16 pages

Welcome To The Case Study!: Hugo Bowne-Anderson

This document discusses Python tools for data science, including using zip() to combine lists, defining functions, list comprehensions, generators for streaming data, and using pandas' read_csv iterator. The document provides examples of building generator functions and reading CSV files in chunks to work with large datasets. Finally, it encourages practicing the skills covered in working with functions, iterators, list comprehensions, and generators.

Uploaded by

vrhdzv
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 16

Welcome to the

case study!
P Y T H O N D ATA S C I E N C E T O O L B O X ( PA R T 2 )

Hugo Bowne-Anderson
Data Scientist at DataCamp
World bank data
Data on world economies for over half a century

Indicators
Population

Electricity consumption

CO2 emissions

Literacy rates

Unemployment

Mortality rates

PYTHON DATA SCIENCE TOOLBOX (PART 2)


Using zip()
avengers = ['hawkeye', 'iron man', 'thor', 'quicksilver']
names = ['barton', 'stark', 'odinson', 'maximoff']
z = zip(avengers, names)
print(type(z))

<class 'zip'>

print(list(z))

[('hawkeye', 'barton'), ('iron man', 'stark'),


('thor', 'odinson'), ('quicksilver', 'maximoff')]

PYTHON DATA SCIENCE TOOLBOX (PART 2)


Defining a function
raise.py

def raise_both(value1, value2):


"""Raise value1 to the power of value2
and vice versa."""
new_value1 = value1 ** value2
new_value2 = value2 ** value1
new_tuple = (new_value1, new_value2)
return new_tuple

PYTHON DATA SCIENCE TOOLBOX (PART 2)


Re-cap: list comprehensions
Basic

[output expression for iterator variable in iterable]

Advanced

[output expression +
conditional on output for iterator variable in iterable +
conditional on iterable]

PYTHON DATA SCIENCE TOOLBOX (PART 2)


Let's practice!
P Y T H O N D ATA S C I E N C E T O O L B O X ( PA R T 2 )
Using Python
generators for
streaming data
P Y T H O N D ATA S C I E N C E T O O L B O X ( PA R T 2 )

Hugo Bowne-Anderson
Data Scientist at DataCamp
Generators for the large data limit
Use a generator to load a le line by line

Works on streaming data!

Read and process the le until all lines are exhausted

PYTHON DATA SCIENCE TOOLBOX (PART 2)


Build a generator function
sequence.py

def num_sequence(n):
"""Generate values from 0 to n."""
i = 0
while i < n:
yield i
i += 1

PYTHON DATA SCIENCE TOOLBOX (PART 2)


Let's practice!
P Y T H O N D ATA S C I E N C E T O O L B O X ( PA R T 2 )
Using pandas'
read_csv iterator for
streaming data
P Y T H O N D ATA S C I E N C E T O O L B O X ( PA R T 2 )

Hugo Bowne-Anderson
Data Scientist at DataCamp
Reading files in chunks
Up next:
read_csv() function and chunk_size argument

Look at speci c indicators in speci c countries

Write a function to generalize tasks

PYTHON DATA SCIENCE TOOLBOX (PART 2)


Let's practice!
P Y T H O N D ATA S C I E N C E T O O L B O X ( PA R T 2 )
Final thoughts
P Y T H O N D ATA S C I E N C E T O O L B O X ( PA R T 2 )

Hugo Bowne-Anderson
Data Scientist at DataCamp
You’ve applied your skills in:
User-de ned functions

Iterators

List comprehensions

Generators

PYTHON DATA SCIENCE TOOLBOX (PART 2)


Let's practice!
P Y T H O N D ATA S C I E N C E T O O L B O X ( PA R T 2 )

You might also like