Essential Python Libraries for Modern Development

Pendulum

For handling date and time operations in Python, Pendulum stands out as a powerful alternative to the standard library. It enhances datetime functionality with an intuitive interface for timezone management and temporal calculations.

Installation

pip install pendulum

Usage Examples

Creating DateTime Objects

import pendulum

dt = pendulum.datetime(2023, 6, 8)
print(dt)

Output:

2023-06-08T00:00:00+00:00

Using Local Timezone

local = pendulum.local(2023, 6, 8)
print("Local time:", local)
print("Timezone:", local.timezone.name)

Output:

Local time: 2023-06-08T00:00:00+08:00
Timezone: Asia/Shanghai

Working with UTC

utc = pendulum.now('UTC')
print("Current UTC time:", utc)

Output:

Current UTC time: 2023-06-08T10:44:51.856673+00:00

Converting Timezones

europe = utc.in_timezone('Europe/Paris')
print("Paris current time:", europe)

Output:

Paris current time: 2023-06-08T12:47:27.836789+02:00

FTFY

When dealing with text encoding issues, FTFY offers a solution for fixing corrupted characters often referred to as "Mojibake".

Installation

pip install ftfy

Example Usage

import ftfy

print(ftfy.fix_text('Correct the sentence using “ftfyâ€\x9d.'))
print(ftfy.fix_text('âœ" No problems with text'))
print(ftfy.fix_text('à perturber la réflexion'))

Beyond fixing Mojibake, FTFY corrects improper encodings, line endings, and qoutation marks. It supports decoding from various character sets including Latin-1, Windows-1252, and more.

Sketch

Sketch is a AI-powered coding assistant tailored for pandas users. It leverages machine learning to provide context-aware code suggestions, streamlining data manipulation tasks.

Installation

pip install sketch

Example Usage

import sketch
import pandas as pd

file = "D://7 Datasciense//DS_visilization//altair//airports.csv"
df = pd.read_csv(file)

# Querying column types
result = df.sketch.ask("Which columns are category type?")
print(result)

# Checking dataframe dimensions
shape_result = df.sketch.ask("What is the shape of the dataframe")
print(shape_result)

# Generating visualization code
visualize_code = df.sketch.howto("Visualize the emotions")
print(visualize_code)

Pgeocode

Pegocode facilitates geospatial analysis by providing geographic information based on postal codes.

Installation

pip install pgeocode

Example Usage

import pgeocode

# Querying location data for Indian postal codes
nomi = pgeocode.Nominatim('in')
locations = nomi.query_postal_code(["620018", "620017", "620012"])
print(locations)

# Calculating distance between postal codes
distance = pgeocode.GeoDistance('in')
distance_result = distance.query_postal_code("620018", "620012")
print(distance_result)

Rembg

Rembg simplifies background removal from images.

Installation

pip install rembg

Example Usage

from rembg import remove
import cv2

input_path = 'image.jpeg'
output_path = 'output.jpeg'

input_image = cv2.imread(input_path)
output_image = remove(input_image)
cv2.imwrite(output_path, output_image)

Humanize

Humanize transforms numerical and temporal data into readable formats.

Installation

pip install humanize

Example Usage

import humanize
import datetime as dt

# Formatting numbers
formatted_number = humanize.intcomma(951009)
word_number = humanize.intword(10046328394)

print(formatted_number)
print(word_number)

# Date formatting
natural_date = humanize.naturaldate(dt.date(2012, 6, 5))
natural_day = humanize.naturalday(dt.date(2012, 6, 5))

print(natural_date)
print(natural_day)

Output:

951,009
10.0 billion
Jun 05 2012
Jun 05

OSMNX

OSMNX is excellent for retrieving spatial data about locations through OpenStreetMap.

Example Usage

import osmnx as ox
import pandas as pd

# Define parameters
places = ["restaurant", "bar"]
cities = ["Berlin, Germany", "Hamburg, Germany"]
years = ["2020", "2021"]

# Retrieve OSM data
for place in places:
    for city in cities:
        for year in years:
            tags = {"amenity": place}
            data = ox.geometries_from_place(city, tags=tags)
            data["snap_year"] = year
            # Save data
            filename = f"{place}_{year}_{city}.csv"
            data.to_csv(filename)

This approach allows collecting structured spatial data from OSM for specific categories across multiple years and locations.

Tags: python Libraries datetime data-processing ai-tools

Posted on Wed, 30 Sep 2026 16:45:49 +0000 by enfys