TheDeveloperBlog.com

Home | Contact Us

C-Sharp | Java | Python | Swift | GO | WPF | Ruby | Scala | F# | JavaScript | SQL | PHP | Angular | HTML

Pandas Multiple Index

Pandas Multiple Index with What is Python Pandas, Reading Multiple Files, Null values, Multiple index, Application, Application Basics, Resampling, Plotting the data, Moving windows functions, Series, Read the file, Data operations, Filter Data etc.

<< Back to PANDAS

Multiple Index

Multiple indexing is defined as a very essential indexing because it deals with the data analysis and manipulation, especially for working with higher dimensional data. It also enables to store and manipulate data with the arbitrary number of dimensions in lower dimensional data structures like Series and DataFrame.

It is the hierarchical analogue of the standard index object which is used to store the axis labels in pandas objects. It can also be defined as an array of tuples where each tuple is unique. It can be created from a list of arrays, an array of tuples, and a crossed set of iterables.

Example:

arrays = [['it', 'it', 'of', 'of', 'for', 'for', 'then', 'then'],
['one', 'two', 'one', 'two', 'one', 'two', 'one', 'two']]
tuples = list(zip(*arrays))
tuples

Output:

 [('it', 'one'),
 ('it', 'two'),
 ('of', 'one'),
 ('of', 'two'),
 ('for', 'one'),
 ('for', 'two'),
 ('then', 'one'),
 ('then', 'two')]

Example2:

arrays = [['it', 'it', 'of', 'of', 'for', 'for', 'then', 'then'],
['one', 'two', 'one', 'two', 'one', 'two', 'one', 'two']]
tuples = list(zip(*arrays))
index = pd.MultiIndex.from_tuples(tuples, names=['first', 'second'])

Output:

MultiIndex([('bar', 'one'),
 [('it', 'one'),
 ('it', 'two'),
 ('of', 'one'),
 ('of', 'two'),
 ('for', 'one'),
 ('for', 'two'),
 ('then', 'one'),
 ('then', 'two')]
 names=['first', 'second'])

Example3:

import pandas as pd
import numpy as np
pd.MultiIndex(levels=[[np.nan, None, pd.NaT, 128, 2]], 
codes=[[0, -1, 1, 2, 3, 4]])

Output:

MultiIndex(levels=[[nan, None, NaT, 128, 2]],
           codes=[[0, -1, 1, 2, 3, 4]])

Next TopicPandas Reindex




Related Links:


Related Links

Adjectives Ado Ai Android Angular Antonyms Apache Articles Asp Autocad Automata Aws Azure Basic Binary Bitcoin Blockchain C Cassandra Change Coa Computer Control Cpp Create Creating C-Sharp Cyber Daa Data Dbms Deletion Devops Difference Discrete Es6 Ethical Examples Features Firebase Flutter Fs Git Go Hbase History Hive Hiveql How Html Idioms Insertion Installing Ios Java Joomla Js Kafka Kali Laravel Logical Machine Matlab Matrix Mongodb Mysql One Opencv Oracle Ordering Os Pandas Php Pig Pl Postgresql Powershell Prepositions Program Python React Ruby Scala Selecting Selenium Sentence Seo Sharepoint Software Spellings Spotting Spring Sql Sqlite Sqoop Svn Swift Synonyms Talend Testng Types Uml Unity Vbnet Verbal Webdriver What Wpf