4

Data Structures: lists, tuples, sets, dictionaries, and more advanced data structures like numpy arrays and pandas dataframes in python

Blogprogrammingpythonpython programming course

Below are the overview of common data structures in Python:

  • Lists: Lists are ordered collections of items, enclosed in square brackets []. They can hold a mix of data types, including other lists. Lists are mutable, meaning they can be modified after creation. You can access, add, and delete elements from a list using indexing, slicing, and methods such as append(), insert(), and remove(). Here’s an example of creating a list and using some of these methods:
  • Tuples: Tuples are similar to lists but are immutable, meaning they cannot be modified after creation. They are enclosed in parentheses (). You can access elements in a tuple using indexing, just like a list. However, you cannot add or remove elements from a tuple. Here’s an example of creating a tuple and accessing elements:
  • Sets: Sets are unordered collections of unique items, enclosed in curly braces {}. They can be used to remove duplicates from a list or to check for membership.
  • Dictionaries: Dictionaries are unordered collections of key-value pairs, enclosed in curly braces {}. The keys must be unique and immutable, while the values can be of any type. You can access, add, and delete elements from a dictionary using the keys. Here’s an example of creating a dictionary and using some of these methods:
  • Numpy arrays: Numpy is a library for the Python programming language, adding support for large, multi-dimensional arrays and matrices, along with a large collection of high-level mathematical functions to operate on these arrays. The numpy arrays are more efficient than python lists and are mostly used in Data Science and Machine Learning projects.
  • Pandas Dataframe: Pandas is a library for the Python programming language, providing fast, flexible, and expressive data structures designed to make working with “relational” or “labeled” data both easy and intuitive. Dataframe is the most commonly used data structure in Pandas, it is a 2-dimensional size-mutable, tabular data structure with rows and columns. Here’s an example of creating a dataframe and using some of its methods:

It is important to note that there are various other methods available in pandas library for data manipulation and data analysis such as filtering, groupby, merge, etc.

Leave a Reply

Your email address will not be published. Required fields are marked *