What Is The Difference Between Tuple,Dictionary and Series In Python

What Is The Difference Between Tuple,Dictionary and Series In Python

A tuple is an immutable sequence type in Python. It is similar to a list which can contains elements of various types, but once the tuple is created, it cannot be modified or changed and that's why tuple is called as immutable.Parentheses () are used to define tuples, and commas are used to separate elements of the tuple.Tuple is one of 4 built-in data types in Python used to store collections of data.Using square brackets we can get the values from tuples in Python.


To know more about Tuple click here.

Dictionaries are kind oa data structure provided by Python which is more generally known as an associative array.A dictionary mainly consists of key value pair.Each key-value pair maps the key to its associated value.The key values of the dictionary is unique and the key values are used to retrieve the corresponding values of the keys from the dictionary.Curly braces are used to define dictionaries, which are made up of key-value pairs separated by a colon:.

A Series is genearlly a one-dimensional labeled array which can hold any type of data into it.Each value in a pandas series is associated with the index. The default index value of it is from 0 to number – 1, or you can specify your own index values.Series is a very useful component of the pandas library, which is a powerful Python library for data analysis and manipulation. A Series can be created from a list or an array, and each element of series has a label.


Here is how you can create each within Python:


# How to create a tuple

tup = (5, 'W', 2.67)


# How to create a dictionary

dict = {'key4': 4, 'key5': '8', 'key6': 5.98}


# How to create a Series

import pandas as pd

ser = pd.Series([4, '8', 7.89], index=['k1', 'k2', 'k3'])

Comments