• Skip to main content
  • Skip to secondary menu
  • Skip to primary sidebar
  • Skip to footer
  • Home
  • Crypto Currency
  • Technology
  • Contact
NEO Share

NEO Share

Sharing The Latest Tech News

  • Home
  • Artificial Intelligence
  • Machine Learning
  • Computers
  • Mobile
  • Crypto Currency

How to Boost Pandas Functions with Python Dictionaries

March 3, 2021 by systems

Soner Yıldırım

Explained with examples

Photo by Bill Jelen on Unsplash

Pandas is a highly popular data analysis and manipulation library. Thanks to the simple and intuitive Python syntax, Pandas is usually the first choice for aspiring data scientist. Its powerful and efficient functions make a great amount of experienced data scientists to prefer Pandas as well.

Pandas provides a rich selection of functions that expedite the data analysis process. The default parameter settings do a fine job in most cases but we can do better by customizing the parameters.

In addition to a constant value or list, some parameters accept a dictionary argument. In this article, we will go over several examples to demonstrate how using dictionaries add value to functions.

We will use a small sample from the Melbourne housing dataset available on Kaggle for the examples. We first read the csv file using the read_csv function.

import numpy as np
import pandas as pd
cols =['Price','Landsize','Distance','Type','Regionname']melb = pd.read_csv(
"/content/melb_data.csv",
usecols = cols,
dtype = {'Price':'int'},
na_values = {'Landsize':9999, 'Regionname':'?'}
)
melb.head()
(image by author)

The dtype parameter is used to specify the data types. By using a dictionary, we are able to specify the data type for each column separately.

The real life data is usually messy so we are likely to encounter different representations of missing values. The na_values parameter handles such representations.

Consider a case where the missing values in the land size and region name columns are represented with 9999 and “?”, respectively. We can pass a dictionary to the na_values parameter to handle column-specific missing values.

Filed Under: Artificial Intelligence

Primary Sidebar

Stay Ahead: The Latest Tech News and Innovations

Cryptocurrency Market Updates: What’s Happening Now

Emerging Trends in Artificial Intelligence: What to Watch For

Top Cloud Computing Services to Secure Your Data

The Future of Mobile Technology: Recent Advancements and Predictions

Footer

  • Privacy Policy
  • Terms and Conditions

Copyright © 2025 NEO Share

Terms and Conditions - Privacy Policy