In Python, we have a type of container similar to dictionaries known as namedtuples() which is present in the module collection. Similar to dictionaries, they have keys that are hashed to a particular value. It supports both access from key value and iteration. This is the functionality which the dictionaries lack in python while applying it on data science.
Operations on namedtuple():
- Access by index: In namedtuple() the attribute values are order, and these can be access using the index number. But in dictionaries, it is not accessible by index.
- Access by keyname: Similar to dictionaries access by keyname is allowed.
- using getattr(): It is another way of accessing the value by giving namedtuple and key value as argument.
- _make(): When this function is call it returns a namedtuple() from the iterable pass as argument.
- _asdict(): When this function is call, it returns the Orderedict() as it is constructed from the map values of namedtuple().
- using “**” (double star) operator: This is a function that is there for converting a dictionary into namedtuple().
- _fields: It is a function that is there for returning all the keynames of the namespace declare.
- _replace(): It is a function that is there for changing the values map with pass keyname.
To learn more about it python for data science, you can check this and this as well. These blogs will help you in getting more insights of how the data science industry looks like. If you are looking for related course then it will help you in getting that as well.