Python Articles

Page 824 of 852

How do I disable log messages from the Requests Python module?

Rajendra Dharmkar
Rajendra Dharmkar
Updated on 11-Dec-2019 1K+ Views

You can disable logging from the requests module using the logging module.ExampleYou can configure it to not log messages unless they are at least warnings using the following code:import logging logging.getLogger("requests").setLevel(logging.WARNING)If you want to go a level higher and only want to log messages when they are errors or critical, you can do replace logging.WARNING with logging.ERROR and logging.CRITICAL respectively.

Read More

How to extract subset of key-value pairs from Python dictionary object?

Jayashree
Jayashree
Updated on 04-Dec-2019 3K+ Views

Use dictionary comprehension technique.We have dictionary object having name and percentage of students>>> marks = {    'Ravi': 45.23,    'Amar': 62.78,    'Ishan': 20.55,    'Hema': 67.20,    'Balu': 90.75 }To obtain dictionary of name and marks of students with percentage>50>>> passed = { key:value for key, value in marks.items() if value > 50 } >>> passed {'Amar': 62.78, 'Hema': 67.2, 'Balu': 90.75}To obtain subset of given names>>> names = { 'Amar', 'Hema', 'Balu' } >>> lst = { key:value for key,value in marks.items() if key in names} >>> lst {'Amar': 62.78, 'Hema': 67.2, 'Balu': 90.75}

Read More

Difference between Python and PHP.

Mahesh Parahar
Mahesh Parahar
Updated on 28-Nov-2019 575 Views

PythonPython is a high level programming language with inbuilt big library and is used to develop standalone programs. It was developed by Guido Van Rossum and its first version was released in the year 1990.PHPPHP stands for Hypertext Preprocessor, it is server side scripting language. It was developed in 1995. It is used to create dynamic web based pages.Following are the important differences between Python and PHP.Sr. No.KeyPythonPHP1Learning CurvePython requires good effort if one learns from scratch. It is similar to C++ and Java.PHP is easy to learn if user knows html and javascript.2FrameworksPopular Python frameworks are Flask, DJango.Popular PHP ...

Read More

Find the version of the Pandas and its dependencies in Python

Arnab Chakraborty
Arnab Chakraborty
Updated on 04-Nov-2019 272 Views

Pandas is the important package for data analysis in Python. There are different versions available for Pandas. Due to some version mismatch, it may create some problems. So we need to find the version numbers of the Pandas. We can see them easily using the following code.We can use the command like below, to get the version −pandas.__version__Example>>> import pandas as pd >>> print(pd.__version__) 0.25.2 >>>We can also get the version of the dependencies using the function like below −pandas.show_versions() >>> pd.show_versions() INSTALLED VERSIONS ------------------ commit : None python : 3.7.1.final.0 python-bits : 64 OS : Windows OS-release : 7 ...

Read More

Apply function to every row in a Pandas DataFrame in Python

Hafeezul Kareem
Hafeezul Kareem
Updated on 01-Nov-2019 1K+ Views

In this tutorial, we are going to learn about the most common methods of a list i.e.., append() and extend(). Let's see them one by one.apply()It is used to apply a function to every row of a DataFrame. For example, if we want to multiply all the numbers from each and add it as a new column, then apply() method is beneficial. Let's see different ways to achieve it.Example# importing the pandas package import pandas as pd # function to multiply def multiply(x, y):    return x * y # creating a dictionary for DataFrame data = {    'Maths': ...

Read More

Apply uppercase to a column in Pandas dataframe in Python

Hafeezul Kareem
Hafeezul Kareem
Updated on 01-Nov-2019 2K+ Views

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.ExampleWe can assign a column to the DataFrame by making it uppercase using the upper() method.Let's see the code.# importing the pandas package import pandas as pd # data for DataFrame data = {    'Name': ['Hafeez', 'Aslan', 'Kareem'],    'Age': [19, 21, 18],    'Profession': ['Developer', 'Engineer', 'Artist'] } # creating DataFrame data_frame = pd.DataFrame(data) # displaying the DataFrame print('---------------------Before-------------------') print(data_frame) print() # making the Name column strings to upper case data_frame['Name'] = ...

Read More

Arithmetic Operations on Images using OpenCV in Python

Hafeezul Kareem
Hafeezul Kareem
Updated on 01-Nov-2019 1K+ Views

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==4.1.1.26If you run the above command, you will get the following successful message.Collecting opencv-python==4.1.1.26 Downloading https://files.pythonhosted.org/packages/1f/51/e0b9cef23098bc31c77b0e0 6221dd8d05119b9782d4c2b1d1482e22b5f5e/opencv_python-4.1.1.26-cp37-cp37m-win_amd64.w hl (39.0MB) Requirement already satisfied: numpy>=1.14.5 in c:\users\hafeezulkareem\anaconda3\l ib\site-packages (from opencv-python==4.1.1.26) (1.16.2) Installing collected packages: opencv-python Successfully installed opencv-python-4.1.1.26AdditionWe can add two images using ...

Read More

as_integer_ratio() in Python for reduced fraction of a given rational

Hafeezul Kareem
Hafeezul Kareem
Updated on 01-Nov-2019 471 Views

In this tutorial, we are going to write a program that returns two numbers whose ratio is equal to the given float value. We have a method called as_integer_ratio() that helps to achieve our goal.Let's see some examples.Input: 1.5 Output: 3 / 2 Input: 5.3 Output: 5967269506265907 / 1125899906842624Let's examine the code.Example# initializing the float value float_value = 1.5 # getting integers tuple using the as_integer_ratio() method integers = float_value.as_integer_ratio() # printing the integers print(f'{integers[0]} / {integers[1]}')OutputIf you run the above code, you will get the following results.3 / 2 Let's see another example.Example# initializing the float value float_value = ...

Read More

Audio processing using Pydub and Google Speech Recognition API in Python

Hafeezul Kareem
Hafeezul Kareem
Updated on 01-Nov-2019 948 Views

In this tutorial, we are going to work with the audio files. We will breakdown the audio into chunks to recognize the content in it. We will store the content of the audio files in text files as well. Install the following modules using the below commands.pip install pydubIf you run the above command, you will get the following successful messageCollecting pydub Downloading https://files.pythonhosted.org/packages/79/db/eaf620b73a1eec3c8c6f8f5 b0b236a50f9da88ad57802154b7ba7664d0b8/pydub-0.23.1-py2.py3-none-any.whl Installing collected packages: pydub Successfully installed pydub-0.23.1pip install audioreadIf you run the above command, you will get the following successful message.Collecting audioread Downloading https://files.pythonhosted.org/packages/2e/0b/940ea7861e0e9049f09dcfd 72a90c9ae55f697c17c299a323f0148f913d2/audioread-2.1.8.tar.gz Building wheels for collected packages: audioread Building wheel for audioread ...

Read More

Barnsley Fern in Python

Hafeezul Kareem
Hafeezul Kareem
Updated on 01-Nov-2019 509 Views

In this tutorial, we are going to learn about the Barnsley Fern, which is created by Michael Barnsley. The features of Barnsley Fern is similar to the fern shape. It is created by iterating over the four mathematical equations known as Iterated Function System(IFS). The transformation has the following formula.f(x, y)=$$\begin{bmatrix}a & b \c & d \end{bmatrix}\begin{bmatrix}x \y \end{bmatrix}+\begin{bmatrix}e \f \end{bmatrix}$$Source − WikipediaThe values of the variables are −Source − WikipediaThe four equation that Barnsley Fern proposed are −Source − WikipediaNow, we will see code to create the fern shape in Python.Example# importing matplotlib module for the plot import matplotlib.pyplot ...

Read More
Showing 8231–8240 of 8,519 articles
« Prev 1 822 823 824 825 826 852 Next »
Advertisements