- Trending Categories
- Data Structure
- Operating System
- MS Excel
- C Programming
- Social Studies
- Fashion Studies
- Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
What are the data structures in the Python pandas package?
The data structure is a way of collecting data, organizing, and storing format that enables us to access and modify data in an efficient way. It is a collection of data types. It gives you the best way of organizing the items(values) in terms of memory.
The python pandas package handles data in an effective way because it has two powerful data structures named Series and DataFrames.
Series is nothing but a one-dimensional labeled array, which can be capable of holding any data type. it can store integer values, strings, floating-point numbers, etc. Each and every value in a Series is assigned to a label(assigned to an index), labels may be integer values or they may be a name representation.
import pandas as pd data = pd.Series([1,2,3,4,5]) print(data)
Pandas Series data structure is defined by using a simple python list with 5 elements. By using the import keyword we have imported the pandas package and then we created the Series by using pandas. Series function.
0 1 1 2 2 3 3 4 4 5 dtype: int64
The output of the Series is represented in the above block, we can observe that the pandas series is a 1-Dimensional object which stores homogeneous data and each value in a Series is represented by a label. For our above example label values are 0,1,2,3,4.
The other data structure in pandas is DataFrame, which is a 2-Dimensional labeled data structure used to represent in rows and columns format. Data present in each column may have different data types. The total structure of a DataFrame looks similar to a spreadsheet or SQL table. Like Series, DataFrame rows are also represented with labels.
import pandas as pd df = pd.DataFrame([[2,3,4,5],[6,7,8,9]], columns=['a','b','c','d']) print(df)
In this above example, we have created a simple pandas DataFrame by using a list of lists, and here the column labels are manually defined as a,b,c,d.
a b c d 0 2 3 4 5 1 6 7 8 9
The output of pandas DataFrame can be seen in the above output block, the DataFrame is created with 2 rows and 4 columns, 0,1 and a,b,c,d are the respective rows and columns labels.
Before pandas 0.20.0 version, there is a 3-Dimensional data structure available, that data structure is called a panel. In newer versions of pandas, these panels’ 3-Dimensional data is represented as a MultiIndex DataFrame.
- Related Articles
- What are compound data types and data structures in Python?
- How to install pandas using the python package manager?
- Inbuilt Data Structures in Python
- What are various Text data types in Python pandas?
- What are the specifications and operations of data structures in compiler design?
- In-built Data Structures in Python
- How to implement immutable Data structures in Python?
- Python – Reshape the data in a Pandas DataFrame
- What are the advantages of using the python pandas library?
- Abstract Data Type in Data Structures
- How to import Pandas package?
- Python - Return an array representing the data in the Pandas Index
- What is an in-memory Queue in Data Structures?
- What are stack and unstack functions in the Python Pandas library.