Article Categories
- All Categories
-
Data Structure
-
Networking
-
RDBMS
-
Operating System
-
Java
-
MS Excel
-
iOS
-
HTML
-
CSS
-
Android
-
Python
-
C Programming
-
C++
-
C#
-
MongoDB
-
MySQL
-
Javascript
-
PHP
-
Economics & Finance
Python Articles
Page 137 of 855
Python Program to get the first given number of items from the array
An array is a data structure of a set of items with the same data type, and each element is identified by an index. In Python, we can get the first few items from an array using slicing syntax array[:n]. Arrays in Python Python does not have its own data structure to represent an array. However, we can use the list data structure as an alternative to the arrays. Here we will use list as an array − numbers = [10, 4, 11, 76, 99] print(numbers) [10, 4, 11, 76, 99] ...
Read MorePython Program to get the last item from the array
An array is a data structure used to store a collection of homogeneous data elements. Each element in the array is identified by an index value or key. Arrays in Python Python doesn't have a built-in data structure to represent arrays, but it has a built-in array module for working with arrays. We can also use the NumPy package. An array defined by the array module is − import array arr = array.array('i', [1, 2, 3, 4]) print(arr) array('i', [1, 2, 3, 4]) A NumPy array defined by the NumPy ...
Read MoreHow to Automate an Excel Sheet in Python?
Excel automation with Python allows you to manipulate spreadsheets programmatically, saving time and reducing manual errors. Python offers several powerful libraries for Excel automation: openpyxl for direct Excel file manipulation, pandas for data analysis operations, and xlwings for advanced Excel integration. Method 1: Using openpyxl Library The openpyxl library provides direct access to Excel files, allowing you to read, write, and modify spreadsheets cell by cell. Installation pip install openpyxl Example Let's create and manipulate an Excel file that adds bonus calculations to employee salaries − import openpyxl as xl ...
Read MoreGet the day from a date in Pandas
Pandas provides several methods to extract the day name from dates. Whether you're working with single dates or multiple date strings, you can use dt.dayofweek, dt.day_name(), or dt.strftime() to get day information in different formats. Using dt.dayofweek with Manual Mapping The dt.dayofweek property returns numeric values (0-6) for days, which you can map to day names ? import pandas as pd # Create a date range dates = pd.date_range(start='2022-01-01', end='2022-01-07') # Create a DataFrame with the dates df = pd.DataFrame({'date': dates}) # Add a column with the day of the week as numbers ...
Read MoreGet the data type of column in Pandas - Python
Pandas is a popular and powerful Python library commonly used for data analysis and manipulation. It offers data structures like Series and DataFrame for working with tabular data. Each column in a Pandas DataFrame can contain a different data type. This article covers various methods for determining column data types in a DataFrame ? Sample DataFrame Let's create a sample DataFrame to demonstrate different approaches ? import pandas as pd # Create a sample dataframe df = pd.DataFrame({ 'Vehicle name': ['Supra', 'Honda', 'Lamborghini'], 'price': [5000000, 600000, ...
Read MoreGet tag name using Beautifulsoup in Python
BeautifulSoup is one of the most widely used Python packages for web scraping and parsing HTML and XML documents. One of the most common tasks when working with HTML and XML documents is extracting the tag name of specific elements. Python's BeautifulSoup library can be installed using the below command ? pip install beautifulsoup4 Using the name Attribute The most straightforward method to get tag names in BeautifulSoup is using the name attribute of the Tag object. This attribute returns a string value containing the name of the tag. Syntax tag.name ...
Read MoreGet specific row from PySpark dataframe
PySpark is a powerful tool for big data processing and analysis. When working with PySpark DataFrames, you often need to retrieve specific rows for analysis or debugging. This article explores various methods to get specific rows from PySpark DataFrames using functional programming approaches. Creating Sample DataFrame Let's create a sample DataFrame to demonstrate all the methods ? from pyspark.sql import SparkSession # Create SparkSession spark = SparkSession.builder.appName("get_specific_rows").getOrCreate() # Create sample DataFrame df = spark.createDataFrame([ ('Row1', 1, 2, 3), ('Row2', 4, 5, 6), ...
Read MoreEmotion classification using NRC Lexicon in Python
Emotion identification or recognition is the ability of a person or system to detect specific emotions from text and categorize them into distinct emotional categories. Unlike traditional sentiment analysis that only classifies text as positive or negative, emotion classification provides deeper insights into human emotions. Emotion Classification in Python using the NRC Lexicon offers a more nuanced approach than basic sentiment analysis. It can identify multiple emotions simultaneously and provides probability scores for each detected emotion. The NRC Emotion Lexicon, developed by the National Research Council of Canada, contains over 27, 000 terms mapped to emotions. It's based ...
Read MoreEmail + Social Logins in Django - Step-by-Step Guide
Email and social logins are essential authentication methods for modern web applications. Email login requires users to provide their email address and password, while social login allows users to authenticate using their existing accounts from platforms like Google or Facebook. In this tutorial, we'll implement both authentication methods in Django using the Django-allauth package. Installation First, install the django-allauth package using pip ? pip install django-allauth Project Setup Step 1: Configure Settings Add the required configurations to your settings.py file ? # settings.py INSTALLED_APPS = [ ...
Read MorePython program to find the smallest word in a sentence
Welcome to this tutorial on writing a Python program to find the smallest word in a sentence. Whether you are a beginner or intermediate Python programmer, this guide will help you learn text manipulation using Python's built-in functions. Problem Statement Given a sentence, we need to find the word with the fewest characters. In case of a tie, we'll return the first occurring smallest word. Using min() with key Parameter The most efficient approach uses the min() function with a key parameter to compare word lengths ? def find_smallest_word(sentence): # ...
Read More