Article Categories
- All Categories
-
Data Structure
-
Networking
-
RDBMS
-
Operating System
-
Java
-
MS Excel
-
iOS
-
HTML
-
CSS
-
Android
-
Python
-
C Programming
-
C++
-
C#
-
MongoDB
-
MySQL
-
Javascript
-
PHP
-
Economics & Finance
Articles by Hafeezul Kareem
Page 6 of 26
Get a google map image of specified location using Google Static Maps API in Python
Google provides a Static Maps API that returns a map image on HTTP request. We can directly request for a map image with different parameters based on our needs. We need to create a billing account on Google to use this API. You can visit the Google Static Maps API documentation for more details on getting an API key. Prerequisites Before starting, make sure you have ? A valid Google Maps API key with Static Maps API enabled The requests module installed (pip install requests) Steps to Get Map Image Follow these ...
Read MoreFind current weather of any city using OpenWeatherMap API in Python
In this tutorial, we will retrieve the current weather of any city using the OpenWeatherMap API in Python. OpenWeatherMap provides a free weather API that allows up to 60 calls per minute without cost. Prerequisites Before getting started, you need to: Create a free account at OpenWeatherMap Generate your API key from the dashboard Install the requests module if not already available Required Modules We need two Python modules for this tutorial − requests − for making HTTP requests to the API json − for parsing the JSON response (built-in module) ...
Read MoreCount all prefixes in given string with greatest frequency using Python
In this tutorial, we will write a Python program that finds all prefixes of a string where one character appears more frequently than another character. This is useful for analyzing character frequency patterns in strings. Given a string and two characters, we need to find all prefixes where the first character has a higher frequency than the second character, then display the count of such prefixes. Examples Example 1 For string "apple" with characters 'p' and 'e' − Input: string = "apple", char1 = 'p', char2 = 'e' Output: ap app appl apple ...
Read MoreBoolean Indexing in Pandas
Boolean indexing in Pandas allows you to select data from DataFrames using boolean vectors. This powerful feature lets you filter rows based on True/False values, either through boolean indices or by passing boolean arrays directly to the DataFrame. Creating a DataFrame with Boolean Index First, let's create a DataFrame with a boolean index vector − import pandas as pd # data data = { 'Name': ['Hafeez', 'Srikanth', 'Rakesh'], 'Age': [19, 20, 19] } # creating a DataFrame with boolean index vector data_frame = pd.DataFrame(data, index=[True, False, ...
Read MoreCalendar Functions in Python -(monthrange(), prcal(), weekday()?)
Python's calendar module provides useful functions for working with dates and calendars. We'll explore three key methods: monthrange(), prcal(), and weekday() for date calculations and calendar display. calendar.monthrange(year, month) The monthrange() method returns a tuple containing the starting weekday number (0=Monday, 6=Sunday) and the number of days in the specified month ? Example import calendar # Getting month information for January 2019 year = 2019 month = 1 weekday, no_of_days = calendar.monthrange(year, month) print(f'First weekday of the month: {weekday}') print(f'Number of days: {no_of_days}') # Let's also check what weekday 1 means weekdays ...
Read MoreAdding a new column to existing DataFrame in Pandas in Python
In this tutorial, we are going to learn how to add a new column to an existing DataFrame in pandas. There are several methods to accomplish this task, each with its own advantages depending on your specific needs. Using Direct Assignment The simplest way to add a new column is by using direct assignment with a list. This method assigns the new column data to the DataFrame like a dictionary element − Example # importing pandas import pandas as pd # creating a DataFrame data = { 'Name': ['Hafeez', 'Aslan', ...
Read MoreApply function to every row in a Pandas DataFrame in Python
In this tutorial, we will learn how to apply functions to every row in a Pandas DataFrame using the apply() method. This is useful when you need to perform calculations across columns or transform data row-wise. The apply() Method The apply() method is used to apply a function along an axis of a DataFrame. When axis=1, it applies the function to each row. This is particularly useful for creating new columns based on calculations involving multiple existing columns. Using Custom Functions with Lambda You can apply custom functions to each row using lambda expressions ? ...
Read MoreApply uppercase to a column in Pandas dataframe in Python
In this tutorial, we are going to see how to make a column of names to uppercase in DataFrame. Let's see different ways to achieve our goal. Using str.upper() Method We can convert a column to uppercase using the str.upper() method. This is the most common and efficient approach for string operations in pandas. # importing the pandas package import pandas as pd # data for DataFrame data = { 'Name': ['Hafeez', 'Aslan', 'Kareem'], 'Age': [19, 21, 18], 'Profession': ['Developer', 'Engineer', 'Artist'] } ...
Read MoreArithmetic Operations on Images using OpenCV in Python
In this tutorial, we are going to learn about the arithmetic operations on Images using OpenCV. We can apply operations like addition, subtraction, Bitwise Operations, etc. Let's see how we can perform operations on images. We need the OpenCV module to perform operations on images. Install the OpenCV module using the following command in the terminal or command line. pip install opencv-python Image Addition We can add two images using the cv2.addWeighted() function. It takes five arguments: two images, the weights for each image, and a scalar value added to the final result. ...
Read Moreas_integer_ratio() in Python for reduced fraction of a given rational
In this tutorial, we are going to write a program that returns two numbers whose ratio is equal to the given float value. The as_integer_ratio() method helps to achieve our goal by converting a float into its exact fractional representation. Let's see some examples ? Input: 1.5 Output: 3 / 2 Input: 5.3 Output: 5967269506265907 / 1125899906842624 Syntax The as_integer_ratio() method is called on a float value and returns a tuple containing the numerator and denominator ? float_value.as_integer_ratio() Return Value Returns a tuple (numerator, denominator) where both are ...
Read More