Convert Numeric Columns to Factor Using dplyr Package in R

Nizamuddin Siddiqui
Updated on 11-Feb-2021 11:36:42

4K+ Views

If we have a numeric column in an R data frame and the unique number of values in the column is low that means the numerical column can be treated as a factor. Therefore, we can convert numeric columns to factor. To do this using dplyr package, we can use mutate_if function of dplyr package.Loading dplyr package and converting numerical columns in BOD data set (available in base R) to factor columns −Examplelibrary(dplyr) str(BOD) 'data.frame': 6 obs. of 2 variables: $ Time : num 1 2 3 4 5 7 $ demand: num 8.3 10.3 19 16 15.6 19.8 - ... Read More

Create Reverse of a Number in R

Nizamuddin Siddiqui
Updated on 11-Feb-2021 11:32:29

2K+ Views

To create reverse of a number, we can use stri_reverse function of stringi package. For example, if we have a vector called x that contain some numbers then the reverse of these numbers will be generated by using the command stri_reverse(x). But the output will be in character form, if we want to have numeric values then as.numeric function can be used.library(stringi)Example Live Demox1

What is Python's sys Module

S Vijay Balaji
Updated on 11-Feb-2021 06:49:05

8K+ Views

IntroductionThe sys module in Python provides valuable information about the Python interpreter. You can also use it to obtain details about the constants, functions and methods of the Python interpreter.Getting StartedThe sys module comes packaged with Python, which means you do not need to download and install it separately using the PIP package manager.In order to start using the sys module and its various functions, you need to import it. You can do that using the below line of code, import sysObtaining the list of argumentsIn python, we can execute the script directly from our terminal using various arguments. Sometimes ... Read More

What is Python's os Module

S Vijay Balaji
Updated on 11-Feb-2021 06:47:49

2K+ Views

IntroductionThe OS module in Python comes with various functions that enables developers to interact with the Operating system that they are currently working on. In this article we’ll be learning mainly to create and delete a directory/folder, rename a directory and even basics of file handling.Without further ado, let’s get started.Getting StartedPython’s OS module comes packaged within python when installed. This means you do not need to separately install it using PIP. In order to access its various methods/functions, you just need to import the module.import osNow that you’ve imported the module, you can start using its various functions.Getting current ... Read More

Reading and Writing Excel Files Using OpenPyXL Module in Python

S Vijay Balaji
Updated on 11-Feb-2021 06:46:38

2K+ Views

Introductionopenpyxl is a Python library to read/write Excel 2010 xlsx/xlsm/xltx/xltm files.It was born from lack of existing library to read/write natively from Python the Office Open XML format.An excel file that we use for operation is called Workbook that contains a minimum of one Sheet and a maximum of tens of sheets.One sheet consists of rows starting from 1 and columns starting from A.Using the openpxyl library, we can perform various functions including adding sheets and data, manipulate and even delete said data.Now that we know what we are dealing with, let us get started.Getting StartedThe openpyxl does not come ... Read More

Validate Data Using Cerberus in Python

S Vijay Balaji
Updated on 11-Feb-2021 06:44:52

2K+ Views

IntroductionThe Cerberus module in python provides powerful yet lightweight data validation functions. It is designed in such a way that you can extend it to various applications and custom validations.We first define a schema and then validate the data against the scheme and check if it matches the provided conditions or not. If not, accurate errors are thrown to display where it went wrong.Various conditions can be applied at once to the data field for validation.Getting startedIn order to use Cerberus, you must first install it, as it does not come packaged with Python.In order to download and install it, ... Read More

Match Patterns and Strings Using the Regex Module in Python

S Vijay Balaji
Updated on 11-Feb-2021 06:42:22

264 Views

IntroductionThe RegEx module stands for Regular expressions. If you have already worked on programming, you would have come across this term several times already. We use the Regular expressions to search and replace, it is used in various text editors, search engines, word processors, etc.In other words, it helps match a certain pattern that you are looking for.A good example for this would be how your collage website allows you to use only your university mail and none of the other extensions.Getting StartedThe regular expression module comes packaged within Python. You do not need to download and install it separately.In ... Read More

Encrypt and Decrypt Data in Python

S Vijay Balaji
Updated on 11-Feb-2021 06:39:10

18K+ Views

IntroductionWhat is cryptography? Cryptography deals with the conversion of plain text into cipher text which is called encryption of data and cipher text back to plain text which is called decryption of data.We will be using the fernet module in the cryptography package to encrypt and decrypt data using Python. While using the fernet module, a unique key is generated without which you cannot read or manipulate the encrypted data.Now that you know what we will be dealing with, let’s get started.Getting StartedThe cryptography module does not come packaged with Python, which means you will have to install it using ... Read More

Create PowerPoint Files Using Python

S Vijay Balaji
Updated on 11-Feb-2021 06:36:51

16K+ Views

IntroductionWe’ve all had to make PowerPoint presentations at some point in our lives. Most often we’ve used Microsoft’s PowerPoint or Google Slides.But what if you don’t have membership or access to the internet? Or what if you just wanted to do it the “programmers” way?Well, worry not for Python’s got your back!In this article you’ll learn how to create a PowerPoint file and add some content to it with the help of Python. So let’s get started!Getting StartedThroughout this walkthrough, we’ll be using the python-pptx package. This package supports different python versions ranging from 2.6 to 3.6.So, make sure you ... Read More

Control Mouse and Keyboard Using Pynput Library in Python

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

5K+ Views

IntroductionThe pynput library allows you to control and monitor/listen to your input devices such as they keyboard and mouse.The pynput.mouse allows you control and monitor the mouse, while the pynput.keyboard allows you to control and monitor the keyboard.In this article, we will be moving the cursor to a specific position, automate clicks, and simulate keystrokes from the keyboard.Without further ado, let’s get started.Getting StartedSince the pynput module does not come packaged with Python, you will have to manually download and install it using the pip package manager.To do this, launch your terminal and use the command below.pip install pynputOnce the ... Read More

Advertisements