Server Side Programming Articles - Page 1896 of 2646

Maximum length of consecutive 1’s in a binary string in Python using Map function

Pradeep Elance
Updated on 04-Feb-2020 06:41:11

479 Views

Sometimes when dealing with the binary representation of numbers we may be needed to find out how many continuous 1’s are present in the number. This article shows two ways how we can find out that.Using Split and MapThe split function in python can be used to split the given string into multiple strings. We split it by zeros and the map function is used to find the maximum length among the splits generated.Example Live Demodata = '11110000111110000011111010101010101011111111' def Max_len_cons_1(data): print ("Maximum Number of consecutive one's: ", max(map(len, data.split('0'))) ) Max_len_cons_1(data)OutputRunning the above code gives us the following result −Maximum Number ... Read More

Usage of Asterisks in Python

Pradeep Elance
Updated on 04-Feb-2020 06:29:16

314 Views

Python programming language uses both * and ** on different contexts. In this article we will see how these two are used and what the respective useful scenarios.As an Infix OperatorWhen * is used as infix operator, it basically gives the mathematical product of numbers. IN the below example we take integers. Floats and complex numbers to multiply and get the results.Example Live Demo# Integers x = 20 y = 10 z = x * y print(z, "") # Floats x1 = 2.5 y1 = 5.1 z1 = x1 * y1 print(z1, "") # Complex Numbers x2 = 4 ... Read More

Statistical Thinking in Python

Pradeep Elance
Updated on 04-Feb-2020 06:22:13

414 Views

Statistics is fundamental to learn ml and AI. As Python is the language of choice for these Technologies, we will see how to write Python programs which incorporate statistical analysis. In this article we will see how to create graphs and charts using various Python modules. This variety of charts help us in analyzing the data quickly and deriving insides are conclusions graphically.Data PreparationWe take the data set containing the data about various seeds. This data set is available at kaggle in the link shown in the program below. It has eight columns which will be used to cerate various ... Read More

Python for Spreadsheet Users

Pradeep Elance
Updated on 04-Feb-2020 06:12:44

259 Views

Excel is the most famous spreadsheet and almost every computer user is comfortable with the idea of managing the data through spreadsheets. Eventually some python program has to interact with excel. Many python libraries are available to create, read and write into excel files. We will see the examples of few such important libraries below.Using openpyxlThis library can read/write Excel 2010 xlsx/xlsm/xltx/xltm files. In the below example we create a excel worksheet, assign data to its cells and finally save the file to a desired location. The module has many in-built methods which can be used for this. We see ... Read More

Predicting Customer Churn in Python

Pradeep Elance
Updated on 04-Feb-2020 06:07:21

644 Views

Every business depends on customer's loyalty. The repeat business from customer is one of the cornerstone for business profitability. So it is important to know the reason of customers leaving a business. Customers going away is known as customer churn. By looking at the past trends we can judge what factors influence customer churn and how to predict if a particular customer will go away from the business. In this article we will use ML algorithm to study the past trends in customer churn and then judge which customers are likely to churn.Data PreparationAs an example will consider the Telecom ... Read More

Fraud Detection in Python

Pradeep Elance
Updated on 04-Feb-2020 05:43:44

3K+ Views

Frauds are really in many transactions. We can apply machine learning algorithms to lies the past data and predict the possibility of a transaction being a fraud transaction. In our example we will take credit card transactions, analyse the data, create the features and labels and finally apply one of the ML algorithms to judge the nature of transaction as being fraud or not. Then we will find out the accuracy, precision as well as f-score of the model we are chosen.Preparing the DataWe in this step we read the source data, study the variables present in it and have ... Read More

Fast XML parsing using Expat in Python

Pradeep Elance
Updated on 04-Feb-2020 05:30:44

1K+ Views

Python allows XML data to be read and processed through its inbuilt module called expat. It is a non-validating XML parser. it creates an XML parser object and captures the attributes of its objects into various handler functions. In the below example we will see how the various handler functions can help us read the XML file as well as give the attribute values as the output data. This generated data can be used for the processing.Exampleimport xml.parsers.expat # Capture the first element def first_element(tag, attrs):    print ('first element:', tag, attrs) # Capture the last element def last_element(tag):   ... Read More

Analyzing Census Data in Python

Yaswanth Varma
Updated on 14-Jul-2025 15:33:52

803 Views

Census data is the source of information collected by the government to understand the population and its characteristics. It consists of details such as age, gender, education, and housing. This helps the government in understanding the current scenario as well as planning for the future. In this article, we are going to learn how to analyze the census data in Python. Python, with its libraries like pandas, numpy, and matplotlib, is widely used for analyzing census data. Analyzing Census Data Here, we are going to use the sample data that consists of the census data stored in ... Read More

Prefix to Infix Conversion in C++

sudhir sharma
Updated on 03-Feb-2020 12:13:21

2K+ Views

In this problem, we are given a prefix expression. Our task is to print the infix conversion of the given expression.Prefix expression is those expressions which have operators before the operands.Example: +AB.Infix expressions are those expressions which have operators between the operands.Example: A+BInfix expression are information for human understanding, but the computer does computations on prefix or postfix expressions (generally postfix).Let’s take an example to understand the problemInput: prefix : /+LM/NX Output: infix : (L+M) / (N/X)To solve this problem, we will be using the stack data structure. We will traverse the prefix expression in reverse order of the expression. ... Read More

Prefix to Postfix Conversion in C++

sudhir sharma
Updated on 03-Feb-2020 12:11:32

4K+ Views

In this problem, we are given a prefix expression. Our task is to print the postfix conversion of the given expression.Prefix expression is those expressions which have operators before the operands.Example: +AB.Postfix expressions are those expressions which have operators after operands in the expressions.Example: AB/The conversion of prefix to postfix should not involve the conversion to infix.Let’s take an example to understand the problem, Input: /+XY+NM Output: XY+NM+/ Explanation: infix -> (X+Y)/(N+M)To solve this problem, we will first traverse the whole postfix expression in an reverse order. And we will be using the stack data structure for our processing. And do ... Read More

Advertisements