Skip to Content
Pandas for Everyone: Python Data Analysis, First Edition
book

Pandas for Everyone: Python Data Analysis, First Edition

by Daniel Y. Chen
December 2017
Beginner to intermediate
410 pages
12h 45m
English
Addison-Wesley Professional
Content preview from Pandas for Everyone: Python Data Analysis, First Edition

J. Tuples

A tuple is similar to a list, in that both can hold heterogeneous bits of information. The main difference is that the contents of a tuple are “immutable,” meaning they cannot be changed. They are also created with a pair of round brackets, ( ).

my_tuple =('a', 1, True, 3.14)

Subsetting items is accomplished in exactly the same ways as for a list (i.e., you use square brackets).

# get the first item print(my_tuple[0])

a

However, if we try to change the contents of an index, we will get an error.

# this will cause an error my_tuple[0] = 'zzzzz'

Traceback (most recent call last):   File "<ipython-input-1-3689669e7d2b>", line 2, in <module>     my_tuple[0] = 'zzzzz' TypeError: ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Start your free trial

You might also like

Pandas for Everyone: Python Data Analysis, 2nd Edition

Pandas for Everyone: Python Data Analysis, 2nd Edition

Daniel Y. Chen

Publisher Resources

ISBN: 9780134547046Purchase book