How to Calculate Euclidean distance in Python

How to Calculate Euclidean distance in Python

To calculate the euclidean distance in Python, use the math.dist() function. The math.dist() is a built-in method that returns the Euclidean distance between two points (x and y), where x and y are the coordinates of that point. Euclidean distance is the widely used technique for finding the distance between two points. This formula can … Read more

How to Filter List in Python

How to Filter List in Python

To filter a list in Python, use the filter() method. The filter() is a built-in Python method that filters the list with the help of a function that tests each item in the list. If it passes the test, it will be included in the output; otherwise not. Let’s see a scenario in which we … Read more

How to Copy Files in Python

How to Copy Files in Python

To copy files in Python, use the shutil.copyfile() method. The shutil.copyfile() method copies the source file’s content to the destination file. The metadata of the file is not copied. Source and destination must represent a file, and destination must be writable. To work with files in Python, file handling is the prerequisite to play with the files … Read more

How to Read CSV File in Python

How to Read CSV File in Python

To read a csv file in Python, use the csv.reader() function. The csv.reader() function reads the file, which returns an iterable reader object. The reader object is then iterated using a for loop to print the contents of each row. CSV stands for Comma Separated Values. It is a file consisting of values separated by values. … Read more

How to Convert File to tar.gz in Python

How to Convert File to tar.gz in Python

To convert a file to tar.gz in Python, use the gzip.open() function. The gzip.open() function opens a gzip-compressed file in binary or text mode, returning a file object. The gzip module provides the open(), compress(), and decompress() convenience functions. Program to convert file to .gz import gzip file = open(“/Users/krunallathiya/Desktop/Code/R/sample.txt”) zipped = gzip.open(“/Users/krunallathiya/Desktop/Code/R/sample.tar.gz”, “wb”) zipped.writelines(file) zipped.close() … Read more

How to Tabulate JSON in Python

How to Tabulate JSON in Python

To tabulate JSON data in Python, use the pd.DataFrame() function. The pd.DataFrame() is a Pandas library function that helps us create two-dimensional, size-mutable, potentially heterogeneous tabular data in Python. JSON stands for JavaScript Object Notation. It is somewhat similar to the Python dictionary. The JSON data type is mainly used to exchange data between clients … Read more

How to Download File from URL in Python

How to Download File from URL in Python

To download a file from a URL in Python, use the requests.get() method. The requests.get() is a library method that sends a GET request to the specified URL. The requests package is a third-party, simple, and elegant HTTP library in Python that provides support to send GET or POST requests to external resources. Downloading multiple … Read more

How to Read String from File in Python

How to Read String from File in Python

To read a string from a file in Python, open a file using with open() function and then use the file.read() function to read a string from the file. The read() is a built-in Python function that reads the file’s content. We can read strings from the file by using the read() function. We can … Read more