Utilize series for data wrangling

Creating Series

pd.Series() method is used to create a pandas Series. In this, a list is given as an argument and we use the index parameter to set the index of the Series. The index helps us to retrieve data based on conditions.

Python3




# importing packages
import pandas as pd
  
# creating a series
population_data = pd.Series([1440297825, 1382345085,
                             331341050,
                             274021604, 212821986],
                            index=['China', 'India'
                                   'United States',
                                   'Indonesia', 'Brazil'])
  
print(population_data)


Output:

 

Filtering data- Retrieving insights based on conditions from the data

From the previous data, we retrieve data on two conditions, one is the population of India and another is countries that have a population of more than a billion.

Python3




print('population of india is : \
' + str(population_data['India']))
  
print('population greater than a billion :')
print(population_data[population_data > 1000000000])


Output:

 

We can also use dictionaries to create Series in python. In this, we have to pass a Dictionary as an argument in the pd.Series() method.

Python3




population_data = pd.Series({'China': 1440297825,
                             'India': 1382345085
                             'United States': 331341050
                             'Indonesia': 274021604,
                             'Brazil': 212821986})
print(population_data)


Output:

 

Changing  indices by altering the index of series

In pd.Series the index can be manipulated or altered by specifying a new index series. 

Python3




population_data.index = ['CHINA','INDIA',
                         'US','INDONESIA',
                         'BRAZIL']
print(population_data)


Output:

 

How to utilise Pandas dataframe and series for data wrangling?

In this article, we are going to see how to utilize Pandas DataFrame and series for data wrangling.

The process of cleansing and integrating dirty and complicated data sets for easy access and analysis is known as data wrangling. As the amount of data raises continually and expands, it is becoming more important to organize vast amounts of data for analysis. Data wrangling comprises activities such as data sorting, data filtering, data reduction, data access, and data processing. Data wrangling is one of the most important tasks in data science and data analysis. Let’s see how to utilize Pandas DataFrame and series for data wrangling.

Similar Reads

Utilize series for data wrangling

Creating Series...

Utilize Pandas Dataframe for data wrangling

...

Contact Us