Convert Excel to CSV in Python

Vikram Chiluka
Updated on 29-Aug-2023 03:49:33

29K+ Views

In this article, we will show you how to convert an excel file to the CSV File (Comma Separated Values) using python. Assume we have taken an excel file with the name sampleTutorialsPoint.xlsx containing some random text. We will return a CSV File after converting the given excel file into a CSV file. sampleTutorialsPoint.xlsx Player Name Age Type Country Team Runs Wickets Virat Kohli 33 Batsman India Royal Challengers Bangalore 6300 20 Bhuvaneshwar Kumar 34 Batsman India Sun Risers Hyderabad 333 140 Mahendra Singh Dhoni 39 Batsman India Chennai Super Kings 4500 ... Read More

Index and Slice a Tuple in Python

Pranav Indukuri
Updated on 29-Aug-2023 03:45:22

36K+ Views

A tuple is an ordered and immutable collection of Python objects separated by commas. Like lists, tuples are sequences. Tuples differ from lists in that they can't be modified, whereas lists can, and they use parentheses instead of square brackets. tup=('tutorials', 'point', 2022, True) print(tup) If you execute the above snippet, produces the following output − ('tutorials', 'point', 2022, True) In this article, we will discuss how to index and slice tuples in python. Indexing Tuples In Python, every tuple with elements has a position or index. Each element of the tuple can be accessed or manipulated by ... Read More

Check if an Object Has an Attribute in Python

Gireesha Devara
Updated on 29-Aug-2023 03:41:46

23K+ Views

Python is an object-oriented programming language, here attributes are known as properties of an object. By using different methods, we can check if an object has an attribute or not. To check if an object contains a particular attribute then we can use hasattr() method and getattr() method. Or if we want to get all existing attributes then we can use the dir() method. (Learn more about Python directories: Python Directories Tutorial) Initially create a dummy Python class with two attributes then assign it to an object, and it will refer throughout this article. class DummyClass(): ... Read More

Creating Instance Objects in Python

Mohd Mohtashim
Updated on 29-Aug-2023 03:34:56

37K+ Views

To create instances of a class, you call the class using class name and pass in whatever arguments its __init__ method accepts."This would create first object of Employee class" emp1 = Employee("Zara", 2000) "This would create second object of Employee class" emp2 = Employee("Manni", 5000)You access the object's attributes using the dot (.) operator with object. Class variable would be accessed using class name as follows −emp1.displayEmployee() emp2.displayEmployee() print "Total Employee %d" % Employee.empCountExampleNow, putting all the concepts together − Live Demo#!/usr/bin/python class Employee:    'Common base class for all employees'    empCount = 0    def __init__(self, name, salary):       ... Read More

Get Longitude and Latitude of a City Using Python

Kiran Kumar Panigrahi
Updated on 29-Aug-2023 03:28:47

32K+ Views

To get the longitude and latitude of a city, we will use the geopy module. geopy uses third-party geocoders and other data sources to locate the coordinates of addresses, cities, countries, etc.First of all, make sure the geopy module is installed −pip install geopyIn the following example, we will use the Nominatim geocoder to find the longitude and latitude of the city "Hyderabad".Steps −Import Nominatim geocoder from geopy module.Initialize the Nominatim API and use the geocode method to get the location of the input string.Finally, get the latitude and longitude of the location by location.latitude and location.longitude.Example 1# Import the ... Read More

Odd Numbers in N-th Row of Pascal's Triangle

Rinish Patidar
Updated on 28-Aug-2023 20:52:29

358 Views

The problem statement includes counting the odd numbers in N−th row of Pascal’s triangle. A pascal’s triangle is a triangular array where each row represents the binomial coefficients in the expansion of binomial expression. The Pascal’s triangle is demonstrated as below: 1 1 ... Read More

Moser-de Bruijn Sequence

Rinish Patidar
Updated on 28-Aug-2023 20:51:30

287 Views

The problem statement includes printing the first N terms of the Moser−de Bruijn Sequence where N will be given in the user input. The Moser−de Bruijn sequence is a sequence consisting of integers which are nothing but the sum of the different powers of 4 i.e. 1, 4, 16, 64 and so on. The first few numbers of the sequence include 0, 1, 4, 5, 16, 17, 20, 21, 64....... The sequence always starts with zero followed by the sum of different powers of 4 such as $\mathrm{4^{0}}$ i.e $\mathrm{4^{1}\:i.e\:4, }$ then sum of $\mathrm{4^{0}\:and\:4^{1}\:i.e\:5}$ and so on. In this ... Read More

Take Integer Input in Python

Tushar Sharma
Updated on 28-Aug-2023 20:49:34

2K+ Views

The acquisition of integer input holds immense significance in various programming tasks, and the Python programming language offers a plethora of techniques to achieve this goal. This article embarks on an insightful journey to explore diverse methodologies for acquiring integer input in Python, focusing on the following strategies: Unveiling the Potential of the `input()` Function and `int()` Type Conversion Harnessing the Versatility of the `map()` Function Unearthing Integer Input from File Sources Attaining Integer Input via Command Line Arguments Method 1: ... Read More

Swap Columns of a Given NumPy Array

Tushar Sharma
Updated on 28-Aug-2023 20:48:11

2K+ Views

When it comes to manipulating NumPy arrays, there might be instances where you want to interchange the positions of two columns. In this article, we delve into four distinct techniques to exchange columns in a given NumPy array: utilizing advanced indexing, employing NumPy indexing, harnessing the np.swapaxes function, and leveraging direct assignment. We will comprehend these methods through illustrative examples. Method 1: Exploiting Advanced Indexing Unleashing the potential of advanced indexing, you open the capability to reshape the course of action of measurements inside a NumPy cluster, much obliged to a choosy curated program of column indices. ... Read More

Suppress Scientific Notations for Small Numbers using NumPy

Tushar Sharma
Updated on 28-Aug-2023 20:45:14

347 Views

When working with NumPy arrays, you may encounter small numbers represented in scientific notation. Although this compact representation is advantageous, deciphering or comparing values can be arduous. This guide delves into four distinct techniques to abate scientific notation usage for diminutive numbers in NumPy arrays: employing numpy.vectorize alongside string formatting, utilizing numpy.ndarray.round, leveraging string formatting, and harnessing numpy.set_printoptions. Examples will elucidate these methodologies, discussing pros and cons, and providing an all-encompassing comprehension of each approach. Method 1: Using numpy.vectorize with string formatting numpy.vectorize function, when combined with string formatting, can suppress scientific notation in NumPy arrays. This approach ... Read More

Advertisements