Server Side Programming Articles - Page 1277 of 2650

How can Tensorflow be used to download flower dataset into the environment?

AmitDiwan
Updated on 19-Feb-2021 17:20:43

416 Views

The flower dataset can be downloaded using a google API that basically links to the flower dataset. The ‘get_file’ method can be used to pass the API as a parameter. Once this is done, the data gets downloaded into the environment.Read More: What is TensorFlow and how Keras work with TensorFlow to create Neural Networks?We will be using the flowers dataset, which contains images of several thousands of flowers. It contains 5 sub-directories, and there is one sub-directory for every class.  We are using the Google Colaboratory to run the below code. Google Colab or Colaboratory helps run Python code ... Read More

How to build a simple GUI calculator using tkinter in Python

S Vijay Balaji
Updated on 11-Feb-2021 06:27:57

909 Views

IntroductionIn Python, we use the tkinter library to create GUI components and craft better user interface.In this article you will learn methods to build a simple GUI based calculator application.Getting startedBefore we jump into it, there are a few things we need to get organised first.Let us start by downloading Python’s imaging library that we will be using to get images from our local system. In order to install PIL(Pillow), launch you terminal and type the command below.pip install PillowNow that you have the package installed. You will have to download icons needed for the calculator.You can go on Google ... Read More

How to access and convert time using the time library in Python

S Vijay Balaji
Updated on 11-Feb-2021 06:19:16

462 Views

IntroductionThe time library in Python is used to obtain time in the real world and perform various tasks related to it. You can even manipulate execution time using this module.Getting StartedThe time module comes packaged with Python. This means you do not have to install it separately using the PIP package manager.In order to use its various functions and methods, you must first import it.import timePrinting current local timeIn order to print the current local time, we will be using the ctime() function.But firstly, we must obtain the number of seconds since epoch. That is, the number of seconds since ... Read More

Documentation generation using the pydoc module in Python

S Vijay Balaji
Updated on 11-Feb-2021 05:53:24

7K+ Views

IntroductionThe pydoc module automatically generates documentation from Python modules. The documentation can be saved as pages of text on the console, displayed on the web browser, or even as HTML files.In this article you will be learning methods to view these documentations in various cases and even learn about docstrings that help you create your own documentation for your python scripts.Now that you know the use of pydoc, let us get started.Getting StartedThe pydoc module comes packaged along with Python, which means you don’t have to download and install it separately.In order to access pydoc, you can must first import ... Read More

Copy and paste to your clipboard using the pyperclip module in Python

S Vijay Balaji
Updated on 11-Feb-2021 05:50:08

2K+ Views

IntroductionWe will be using the pyperclip module in order to copy and paste content to the clipboard. It is cross−platform and works on both Python 2 and Python 3.Copying and pasting from and to the clipboard could be very useful when you want the output of the data to be pasted elsewhere in a different file or software.Getting StartedThe pyperclip module does not come packaged with Python. In order to access it, you must first download and install it. You can do this using the PIP package manager.Launch your terminal and type the command below to install pyperclippip install pyperclipOnce ... Read More

Accessing the internet using the urllib.request module in Python

S Vijay Balaji
Updated on 11-Feb-2021 05:46:33

574 Views

IntroductionWe use the urllib.request module in Python to access and open URLs, which most often use the HTTP protocol.The interface used is also very simple for beginners to use and learn; it uses the urlopen function which can fetch various URLs using a variety of different protocols.You will get a better understanding of what we are working with, once we start using its various functionalities. So, let us get started.Getting StartedThe urllib library comes packaged along with Python. So, you do not need to install it separately, but in case you want to add it to your environment and you ... Read More

Write a Python program to sort a given DataFrame by name column in descending order

Vani Nalliappan
Updated on 24-Feb-2021 07:21:58

645 Views

Input −Assume, sample DataFrame is,   Id Name 0 1 Adam 1 2 Michael 2 3 David 3 4 Jack 4 5 PeterOutput −After, sorting the elements in descending order as,   Id Name 4 5 Peter 1 2 Michael 3 4 Jack 2 3 David 0 1 AdamSolutionTo solve this, we will follow the below approaches.Define a DataFrameApply DataFrame sort_values method based on Name column and add argument ascending=False to show the data in descending order. It is defined below, df.sort_values(by='Name', ascending=False)ExampleLet us see the following implementation to get a better understanding.import pandas as pd data = {'Id': [1, ... Read More

Write a Python function which accepts DataFrame Age, Salary columns second, third and fourth rows as input and find the mean, product of values

Vani Nalliappan
Updated on 24-Feb-2021 07:19:56

592 Views

Input −Assume, sample DataFrame is,  Id Age  salary 0 1 27   40000 1 2 22   25000 2 3 25   40000 3 4 23   35000 4 5 24   30000 5 6 32   30000 6 7 30   50000 7 8 28   20000 8 9 29   32000 9 10 27  23000Output −Result for mean and product of given slicing rows are, mean is Age          23.333333 salary    33333.333333 product is Age                12650 salary    35000000000000SolutionTo solve this, we will follow the below approaches.Define ... Read More

Write a Python program to count the total number of ages between 20 to 30 in a DataFrame

Vani Nalliappan
Updated on 24-Feb-2021 07:15:41

1K+ Views

Input −Assume, you have a DataFrame, Id Age 0 1 21 1 2 23 2 3 32 3 4 35 4 5 18Output −Total number of age between 20 to 30 is 2.SolutionTo solve this, we will follow the below approaches.Define a DataFrameSet the DataFrame Age column between 20,30. Store it in result DataFrame. It is defined below,df[df['Age'].between(20,30)]Finally, calculate the length of the result.ExampleLet us see the following implementation to get a better understanding.import pandas as pd data = {'Id':[1,2,3,4,5],'Age':[21,23,32,35,18]} df = pd.DataFrame(data) print(df) print("Count the age between 20 to 30") result = df[df['Age'].between(20,30)] print(len(result))Output Id Age 0 1 21 1 2 23 2 3 32 3 4 35 4 5 18 Count the age between 20 to 30 2

Write a program in Python to print the ‘A’ grade students’ names from a DataFrame

Vani Nalliappan
Updated on 24-Feb-2021 07:12:02

653 Views

Input −Assume, you have DataFrame,  Id  Name Grade 0 1 stud1   A 1 2 stud2   B 2 3 stud3   C 3 4 stud4   A 4 5 stud5   AOutput −And the result for ‘A’ grade students name, 0    stud1 3    stud4 4    stud5SolutionTo solve this, we will follow the below approaches.Define a DataFrameCompare the value to the DataFramedf[df['Grade']=='A']Store the result in another DataFrame and fetch Name.ExampleLet us see the following implementation to get a better understanding.import pandas as pd data = [[1, 'stud1', 'A'], [2, 'stud2', 'B'], [3, 'stud3', 'C'], [4, 'stud4', 'A'], ... Read More

Advertisements