Found 33676 Articles for Programming

How to check whether you are connected to Internet or not in C#?

Nizamuddin Siddiqui
Updated on 05-Nov-2020 13:37:58

1K+ Views

There are many ways to check whether internet is connected to a machine in C# or not. Make use of System.Net namespace which provides common methods for sending data to and receiving data from a resource identified by a URI. The WebClient or HttpClient class provides common methods for sending data to or receiving data from any local, intranet, or Internet resource identified by a URI. Here in the below example we have used (OpenRead)Returns the data from a resource as a Stream.Checks by hitting the url "http://google.com/generate_204" if success return true else false.The below example runs in the loop ... Read More

How to select a Subset Of Data Using lexicographical slicingin Python Pandas?

Kiran P
Updated on 10-Nov-2020 09:34:45

317 Views

IntroductionPandas have a dual selection capability to select the subset of data using the Index position or by using the Index labels. Inthis post, I will show you how to "Select a Subset Of Data Using lexicographical slicing".Google is full of datasets. Search for movies dataset in kaggle.com. This post uses the movies data set from kaggle.How to do it1. Import the movies dataset with only the columns required for this example.import pandas as pd import numpy as np movies = pd.read_csv("https://raw.githubusercontent.com/sasankac/TestDataSet/master/movies_data.csv", index_col="title", usecols=["title", "budget", "vote_average", "vote_count"]) movies.sample(n=5)titlebudgetvote_averagevote_countLittle Voice06.661Grown Ups 2800000005.81155The Best Years of Our Lives21000007.6143Tusk28000005.1366Operation Chromite05.8292. I always recommend ... Read More

How to select subset of data with Index Labels in Python Pandas?

Kiran P
Updated on 10-Nov-2020 06:32:47

1K+ Views

IntroductionPandas have a dual selection capability to select the subset of data using the Index position or by using the Index labels. Inthis post, I will show you how to “Select a Subset Of Data Using Index Labels” using the index label.Remember, Python dictionaries and lists are built-in data structures that select their data either by using the index label or byindex position. A dictionary’s key must be a string, integer, or tuple while a List must either use integers (the position) or sliceobjects for selection.Pandas have .loc and.iloc attributes available to perform index operations in their own unique ways. ... Read More

How to Find The Largest Or Smallest Items in Python?

Kiran P
Updated on 10-Nov-2020 05:10:16

416 Views

This article is aimed at developers who want to find the largest or smallest items with Python. I will show a few methods touse and will conclude the best method for you.Method – 1: Slice approach on a ListIf you are simply trying to find the single smallest or largest item i.e N = 1, it is faster to use min() and max().Let us begin by generating some random integers.import random # Create a random list of integers random_list = random.sample(range(1, 10), 9) random_listOutput[2, 4, 5, 1, 7, 9, 6, 8, 3] FINDING THE SMALLEST & LARGEST ITEM (N=1) # ... Read More

How to Identify Most Frequently Occurring Items in a Sequence with Python?

Kiran P
Updated on 10-Nov-2020 05:03:25

300 Views

ProblemYou need to identify the most frequently occurring items in a sequence.SolutionWe can use counter to keep track of the items in a sequence.What is a Counter ?The “Counter” is a mapping that holds an integer count for each key. Updating an existing key adds to its count. This Objectis used for counting the instances of hashable objects or as a multiset.The “Counter” is one of your best friends when you are performing data analysis.This object has been present in Python for quite some time, and so for a lot of you, this will be a quick review.We will start ... Read More

How to split strings on multiple delimiters with Python?

SaiKrishna Tavva
Updated on 09-Oct-2024 14:02:07

2K+ Views

Depending on the flexibility and complexity required, we can split a string on multiple delimiters in several ways such as using Python's re.split() method, which is a combination of various string methods. Some of the commonly used approaches to split strings on multiple delimiters. str.replace() and str.split() re.split() Method translate() ... Read More

Count the pairs of vowels in the given string in C++

Sunidhi Bansal
Updated on 02-Nov-2020 06:20:11

366 Views

We are given with a string of characters and the task is to calculate the count of pairs having both the elements as vowels. As we know there are five vowels in English alphabet i.e. a, i, e, o, u and other characters are known as Consonants.Input − string str = "tutorials point”Output − Count the pairs of vowels in the given string are: 2Explanation − From the given string we can form pairs as (t, u), (u, t), (t, o), (o, r), (r, i), (i, a), (a, l), (l, s), (s, p), (p, o), (o, i), (i, n) and ... Read More

Count the number of elements in an array which are divisible by k in C++

Sunidhi Bansal
Updated on 02-Nov-2020 06:18:19

1K+ Views

We are given with an array of positive integer numbers and an integer variable k. The task is to calculate the count of the number of elements in an array which is divisible by the given value k.Input − int arr[] = {4, 2, 6, 1, 3, 8, 10, 9}, k = 2Output − Count the number of elements in an array which are divisible by 2 are − 5Explanation − we will divide the elements in an array by a value k and check whether the reminder is 0 or not. So, 4 is divisible by 2, 2 is ... Read More

Count of character pairs at same distance as in English alphabets in C++

Sunidhi Bansal
Updated on 02-Nov-2020 06:16:00

170 Views

We are given a string of characters and the task is to calculate the count of character pairs having pairs at the same distance as we have in english alphabets.Input − string str = ‘Tutorials Point’Output − Count of character pairs at same distance as in English alphabets are: 5Explanation − The character pairs with same distance as in english alphabets are (u, t), (u, r), (t, r), (i, o) and (s, n). So in total there are 5 pairs.Input − string str = ‘Learning is the best habit’Output − Count of character pairs at same distance as in English ... Read More

Count of numbers having only 1 set bit in the range [0, n] in C++

Sunidhi Bansal
Updated on 02-Nov-2020 06:14:40

259 Views

We are given a number and the task is to calculate the count of numbers from the range 0 till the given number let’s say, num having exactly one set bitSet bits in a binary number is represented by 1. Whenever we calculate the binary number of an integer value then it is formed as the combination of 0’s and 1’s. So, the digit 1 is known as set bit in the terms of the computer.Input − int num = 15Output − Count of numbers having only 1 set bit in the range [0, 15] are − 4Explanation − The ... Read More

Advertisements