Python

What is lambda in Python? Why is it used?

What is lambda in Python? Why is it used?

A lambda function is an anonymous function in Python. syntax → lambda <argument name> : <return expression> It starts with the keyword, followed by a comma-separated list of zero or more arguments, followed by the colon and the return expression. For example, lambda x, y, z: x+y+z would calculate the sum of the three-argument values x+y+z. Use of Lambda Functions uses lambda functions once we require a nameless function for a brief period of your time.Lambda functions reduce the number of lines of code when compared to normal python functions.They are generally used when a function is needed temporarily for a short period…
Read More
Clustering & Visualization of Clusters using PCA

Clustering & Visualization of Clusters using PCA

Customer's Segmentation based on their Credit Card usage behavior Dataset for this notebook consists of the credit card usage behavior of customers with 18 behavioral features. Segmentation of customers can be used to define marketing strategies. Content of this Kernel: Data PreprocessingClustering using KMeansInterpretation of ClustersVisualization of Clusters using PCA # This Python 3 environment comes with many helpful analytics libraries installed # It is defined by the kaggle/python docker image: https://github.com/kaggle/docker-python # For example, here's several helpful packages to load in import numpy as np # linear algebra import pandas as pd # data processing, CSV file I/O (e.g.…
Read More
How do you count repeated words in a list in Python?

How do you count repeated words in a list in Python?

In this post, we will talk about how to count repeated words in python list. It can be done in many ways. Using collections.Counter() # Importing counter function. from collections import Counter words = ["a", "b", "a", "c", "c", "a", "c"] duplicate_dict = Counter(words) print(duplicate_dict)#to get occurence of each of the element. print(duplicate_dict['a'])# to get occurence of specific element. Output: Counter({'a': 3, 'c': 3, 'b': 1}) 3 Using count() letter = ["b", "a", "a", "c", "b", "a", "c",'a'] counting=letter.count('a') print(counting) Output: > 4 Hope this helps! Important Notice for college students If you’re a college student and have skills in programming languages,…
Read More
How do I solve tough programming problems in HackerRank?

How do I solve tough programming problems in HackerRank?

If you are a beginner then go with easy problems first, try to solve as much you can for getting confidence. If, you are not able to solve easy problems then spend some time on that try to think harder, even you can't solve the problem go for editorial read the approach, don't read the code and try to solve your own spend time and practice gives you high return for sure. If you think you can solve easy problems go for a medium one. Go with the same approach as you have done with easy problems…even giving more time…
Read More
What is the difference between the append() and insert() list methods in Python?

What is the difference between the append() and insert() list methods in Python?

Difference between append() and insert () Append(): This function is used to modify an already existing list. Adds a new specific element at the end of the list. Syntax: List_Name.append(item) Insert(): This function also modifies an already existing list. The only difference between append() and insert() is that the insert function allows us to add a specific element at a specified index of the list unlike append() where we can add the element only at end of the list. Syntax: List_Name.insert(index, item) Refer below example for better understanding Important Notice for college students If you’re a college student and have…
Read More
How is the axis indexed in NumPy’s array?

How is the axis indexed in NumPy’s array?

By definition, the axis number of the dimension is the index of that dimension within the array's shape. It is also the position used to access that dimension during indexing. So we'll be learning how is the axis indexed For example, if a 2D array a has shape (5,6), then you can access a[0,0] up to a[4,5]. Axis 0 is thus the first dimension (the "rows"), and axis 1 is the second dimension (the "columns"). In higher dimensions, where "row" and "column" stop really making sense, try to think of the axes in terms of the shapes and indices involved. If you do  .sum(axis=n), for example,…
Read More
Create a digital clock using Python-Turtle

Create a digital clock using Python-Turtle

Prerequisites: Turtle in programming Python. Turtle is a special feature of Python. Using Turtle, we can easily draw on a drawing board. First, we import the turtle module. Then create a window, next we create a turtle object and using the turtle methods we can draw on the drawing board. In this blog we'll be creating a digital clock using turtle and python. Installation:  To install this module type the below command in the terminal. pip install turtle Note: To create a clock we will use the ‘time’ and ‘DateTime’ module of Python also, To install time use the following command:…
Read More
Python Dictionary

Python Dictionary

Dictionary (Dict)  in Python is an unordered collection of data values, used to store data values like a map, which, unlike other Data Types that hold only a single value as an element, Dictionary holds the key: value pair. Key-value is provided in the dictionary to make it more optimized.  Note – Keys in a dictionary don’t allow Polymorphism. Disclamer: It is important to note that Dictionaries have been modified to maintain insertion order with the release of Python 3.7, so they are now ordered collection of data values. Creating a Dictionary In Python, a Dictionary can be created by placing a sequence of…
Read More
How to create a voice recorder in Python

How to create a voice recorder in Python

Python can be used to perform a variety of tasks. One of them is creating a voice recorder. We can use python’s sounddevice module to record and play audio. This module along with the wavio or the scipy module provides the way to save recorded audio. Installation sounddevice: This module provides functions to play and record NumPy arrays containing audio signals. Let’s install it by running the following command: $ pip3 install sounddevice We can use either wavio and scipy to save the recorded audio in file format. We will see both of them here.To install wavio: $ pip3 install wavio To install scipy: $ pip3 install scipy Now, we are done with installing the…
Read More
Stationarity Analysis in Time Series Data

Stationarity Analysis in Time Series Data

Hey Geeks !!! in this blog, we'll dive into the concept of stationarity using time series data. We'll first understand what is time-series data, what is stationarity, why and when data should be stationary etc...We'll use the dataset I created specifically for this blog to analyze whether the data is stationary or not. We'll also see how to convert the non-stationary data to stationary. Index IntroductionImport Libraries and DependenciesDefine TimeSeriesData ClassImport DatasetAccumulating Number of Sales by monthCreate objectStationarity TestsGraphical TestRolling-Statistics TestAugmented Dickey-Fuller Test (ADF)Kwiatkowski-Phillips-Schmidt-Shin Test (KPSS)Zivot-Andrews TestConclusionConvert data to StationaryDerivativesTransformation using Logarithmic FunctionADF TestKPSS TestZivot-Andrews TestRolling-Statistics TestConclusion 1. Introduction 1.1…
Read More