Data Structures in Pandas
Last Updated : 18 Oct, 2021
Pandas is an open-source library that uses for working with relational or labeled data both easily and intuitively. It provides various data structures and operations for manipulating numerical data and time series. It offers a tool for cleaning and processes your data. It is the most popular Python library that is used for data analysis. In this article, We are going to learn about Pandas Data structure.
It supports two data structures:
Series
Pandas is a one-dimensional labeled array and capable of holding data of any type (integer, string, float, python objects, etc.)
Syntax: pandas.Series(data=None, index=None, dtype=None, name=None, copy=False, fastpath=False)
Parameters:
- data: array- Contains data stored in Series.
- index: array-like or Index (1d)
- dtype: str, numpy.dtype, or ExtensionDtype, optional
- name: str, optional
- copy: bool, default False
Example 1: Series holding the char data type.
Python3
import pandas as pd
list = [ 'g' , 'e' , 'e' , 'k' , 's' ]
res = pd.Series( list )
print (res)
|
Output:
Example 2: Series holding the Int data type.
Python3
import pandas as pd
list = [ 1 , 2 , 3 , 4 , 5 ]
res = pd.Series( list )
print (res)
|
Output:
Example 3: Series holding the dictionary.
Python3
import pandas as pd
dic = { 'Id' : 1013 , 'Name' : 'MOhe' ,
'State' : 'Maniput' , 'Age' : 24 }
res = pd.Series(dic)
print (res)
|
Output:

Dataframe
Pandas DataFrame is a two-dimensional size-mutable, potentially heterogeneous tabular data structure with labeled axes (rows and columns). A Data frame is a two-dimensional data structure, i.e., data is aligned in a tabular fashion in rows and columns like a spreadsheet or SQL table, or a dict of Series objects. . Pandas DataFrame consists of three principal components, the data, rows, and columns.
In the real world, a Pandas DataFrame will be created by loading the datasets from existing storage, storage can be SQL Database, CSV file, and Excel file. Pandas DataFrame can be created from the lists, dictionary, and from a list of dictionary etc. Dataframe can be created in different ways here are some ways by which we create a dataframe:
Example 1: DataFrame can be created using a single list or a list of lists.
Python3
import pandas as pd
lst = [ 'Geeks' , 'For' , 'Geeks' , 'is' ,
'portal' , 'for' , 'Geeks' ]
df = pd.DataFrame(lst)
display(df)
|
Output:
Example 2: Creating DataFrame from dict of ndarray/lists.
To create DataFrame from dict of narray/list, all the narray must be of same length. If index is passed then the length index should be equal to the length of arrays. If no index is passed, then by default, index will be range(n) where n is the array length.
Python3
import pandas as pd
data = { 'Name' :[ 'Tom' , 'nick' , 'krish' , 'jack' ],
'Age' :[ 20 , 21 , 19 , 18 ]}
df = pd.DataFrame(data)
display(df)
|
Output:
Selection of column: In Order to select a column in Pandas DataFrame, we can either access the columns by calling them by their columns name.
Python3
import pandas as pd
data = { 'Name' :[ 'Jai' , 'Princi' , 'Gaurav' , 'Anuj' ],
'Age' :[ 27 , 24 , 22 , 32 ],
'Address' :[ 'Delhi' , 'Kanpur' , 'Allahabad' , 'Kannauj' ],
'Qualification' :[ 'Msc' , 'MA' , 'MCA' , 'Phd' ]}
df = pd.DataFrame(data)
print (df[[ 'Name' , 'Qualification' ]])
|
Output:

How to Select Rows and Column from Pandas DataFrame?
Example 1: Selecting rows.
pandas.DataFrame.loc is a function used to select rows from Pandas DataFrame based on the condition provided.
Syntax: df.loc[df[‘cname’] ‘condition’]
Parameters:
- df: represents data frame
- cname: represents column name
- condition: represents condition on which rows has to be selected
Python3
from pandas import DataFrame
Data = { 'Name' : [ 'Mohe' , 'Shyni' , 'Parul' , 'Sam' ],
'ID' : [ 12 , 43 , 54 , 32 ],
'Place' : [ 'Delhi' , 'Kochi' , 'Pune' , 'Patna' ]
}
df = DataFrame(Data, columns = [ 'Name' , 'ID' , 'Place' ])
print ( "Original data frame:\n" )
display(df)
select_prod = df.loc[df[ 'Name' ] = = 'Mohe' ]
print ( "\n" )
print ( "Selecting rows:\n" )
display (select_prod)
|
Output:
Example 2: Selecting column.
Python3
from pandas import DataFrame
Data = { 'Name' : [ 'Mohe' , 'Shyni' , 'Parul' , 'Sam' ],
'ID' : [ 12 , 43 , 54 , 32 ],
'Place' : [ 'Delhi' , 'Kochi' , 'Pune' , 'Patna' ]
}
df = DataFrame(Data, columns = [ 'Name' , 'ID' , 'Place' ])
print ( "Original data frame:" )
display(df)
print ( "Selected column: " )
display(df[[ 'Name' , 'ID' ]] )
|
Output:
Similar Reads
DataFrame vs Series in Pandas
Pandas is a widely-used Python library for data analysis that provides two essential data structures: Series and DataFrame. These structures are potent tools for handling and examining data, but they have different features and applications. In this article, we will explore the differences between S
8 min read
Pandas dataframe.sort_index()
Pandas is one of those packages and makes importing and analyzing data much easier. When working with DataFrames, Pandas is used for handling tabular data. Let's learn Pandas DataFrame sort_index() method, which is used to sort the DataFrame based on index or column labels. Pandas sort_index() funct
3 min read
Creating a Pandas Series
A Pandas Series is like a single column of data in a spreadsheet. It is a one-dimensional array that can hold many types of data such as numbers, words or even other Python objects. Each value in a Series is associated with an index, which makes data retrieval and manipulation easy. This article exp
3 min read
Python | Pandas Series.data
Python is a great language for doing data analysis, primarily because of the fantastic ecosystem of data-centric python packages. Pandas is one of those packages and makes importing and analyzing data much easier. Pandas series is a One-dimensional ndarray with axis labels. The labels need not be un
2 min read
Count Values in Pandas Dataframe
Counting values in Pandas dataframe is important for understanding the distribution of data, checking for missing values or summarizing data. In this article, we will learn various methods to count values in a Pandas DataFrame We will be using below dataframe to learn about various methods: [GFGTABS
3 min read
Data Processing with Pandas
Data Processing is an important part of any task that includes data-driven work. It helps us to provide meaningful insights from the data. As we know Python is a widely used programming language, and there are various libraries and tools available for data processing. In this article, we are going t
10 min read
How to Set Cell Value in Pandas DataFrame?
In this article, we will discuss how to set cell values in Pandas DataFrame in Python. Method 1: Set value for a particular cell in pandas using dataframe.at This method is used to set the value of an existing value or set a new record. [GFGTABS] Python3 # import pandas module import pandas as pd #
2 min read
Pandas DataFrame index Property
In Pandas we have names to identify columns but for identifying rows, we have indices. The index property in a pandas dataFrame allows to identify and access specific rows within dataset. Essentially, the index is a series of labels that uniquely identify each row in the DataFrame. These labels can
6 min read
Streamlined Data Ingestion with Pandas
Data Ingestion is the process of, transferring data, from varied sources to an approach, where it can be analyzed, archived, or utilized by an establishment. The usual steps, involved in this process, are drawing out data, from its current place, converting the data, and, finally loading it, in a lo
9 min read
Python | Pandas dataframe.info()
The `dataframe.info()` function in Pandas proves to be an invaluable tool for obtaining a succinct summary of a dataframe. This function is particularly useful during exploratory analysis, offering a quick and informative overview of the dataset. Leveraging `dataframe.info()` is an efficient way to
4 min read