Found 10476 Articles for Python

Discuss how the sort function can be applied on NumPy arrays in Python?

AmitDiwan
Updated on 10-Dec-2020 13:17:58

635 Views

NumPy refers to ‘Numerical’ ‘Python’. It is a library that contains multidimensional array objects and multiple methods that help in processing the arrays. NumPy can be used to perform a wide variety of operations on arrays. It is used in conjunction with packages like SciPy, Matplotlib and so on. NumPy+Matplotlib can be understood as an alternative to MatLab. It is an open source package, which means it can be used by anyone.The most important object present in NumPy package is an n-dimensional array which is known as ‘ndarray’. It defines the collection of items of the same type. These values ... Read More

How to find contours of an image using scikit-learn in Python?

AmitDiwan
Updated on 10-Dec-2020 13:16:32

1K+ Views

Scikit-learn, commonly known as sklearn is a library in Python that is used for the purpose of implementing machine learning algorithms. It is an open-source library hence it can be used free of cost. This library is built on Numpy, SciPy and Matplotlib libraries.The method of ‘marching squares’ is used to find the contours in an image. The function ‘find_contours’ present in the ‘measure’ class of ‘skimage’ library is used. In this, the values present in the array are interpolated in a linear manner.This way, the precision of the contours in the output image would be much better. If the ... Read More

How to view the pixel values of an image using scikit-learn in Python?

AmitDiwan
Updated on 10-Dec-2020 13:15:04

719 Views

Data pre-processing basically refers to the task of gathering all the data (which is collected from various resources or a single resource) into a common format or into uniform datasets (depending on the type of data).Since real-world data is never ideal, there is a possibility that the data would have missing cells, errors, outliers, discrepancies in columns, and much more.Sometimes, images may not be correctly aligned, or may not be clear or may have a very large size. The goal of pre-processing is to remove these discrepancies and errors.To get the pixels of an image, a built-in function named ‘flatten’ ... Read More

How can scikit-learn library be used to get the resolution of an image in Python?

AmitDiwan
Updated on 10-Dec-2020 13:13:09

425 Views

Data pre-processing basically refers to the task of gathering all the data (which is collected from various resources or a single resource) into a common format or into uniform datasets (depending on the type of data). Since real-world data is never ideal, there is a possibility that the data would have missing cells, errors, outliers, discrepancies in columns, and much more. Sometimes, images may not be correctly aligned, or may not be clear or may have a very large size. The goal of pre-processing is to remove these discrepancies and errors.To get the resolution of an image, a built-in function ... Read More

How to get the mean of columns that contains numeric values of a dataframe in Pandas Python?

AmitDiwan
Updated on 10-Dec-2020 13:11:53

1K+ Views

Sometimes, it may be required to get the mean values of a specific column or mean values of all columns that contains numerical values. This is where the mean() function can be used.The term ‘mean’ refers to finding the sum of all values and dividing it by the total number of values in the dataset.Let us see a demonstration of the same −Example Live Demoimport pandas as pd my_data = {'Name':pd.Series(['Tom', 'Jane', 'Vin', 'Eve', 'Will']), 'Age':pd.Series([45, 67, 89, 12, 23]), 'value':pd.Series([8.79, 23.24, 31.98, 78.56, 90.20]) } print("The dataframe is :") my_df = pd.DataFrame(my_data) print(my_df) print("The mean is :") print(my_df.mean())OutputThe dataframe is ... Read More

How to get the sum of a specific column of a dataframe in Pandas Python?

AmitDiwan
Updated on 10-Dec-2020 13:08:54

1K+ Views

Sometimes, it may be required to get the sum of a specific column. This is where the ‘sum’ function can be used.The column whose sum needs to be computed can be passed as a value to the sum function. The index of the column can also be passed to find the sum.Let us see a demonstration of the same −Example Live Demoimport pandas as pd my_data = {'Name':pd.Series(['Tom', 'Jane', 'Vin', 'Eve', 'Will']), 'Age':pd.Series([45, 67, 89, 12, 23]), 'value':pd.Series([8.79, 23.24, 31.98, 78.56, 90.20]) } print("The dataframe is :") my_df = pd.DataFrame(my_data) print(my_df) print("The sum of 'age' column is :") print(my_df.sum(1))OutputThe dataframe is ... Read More

How to delete a column of a dataframe using the ‘pop’ function in Python?

AmitDiwan
Updated on 10-Dec-2020 13:06:39

329 Views

Dataframe is a two dimensional data structure, where data is stored in a tabular format, in the form of rows and columns.It can be visualized as an SQL data table or an excel sheet representation. A column in a dataframe can be deleted using different methods.We will see the pop function that takes the name of the column that needs to be deleted as a parameter, and deletes it.Example Live Demoimport pandas as pd my_data = {'ab' : pd.Series([1, 8, 7], index=['a', 'b', 'c']), 'cd' : pd.Series([1, 2, 0, 9], index=['a', 'b', 'c', 'd']), 'ef' : pd.Series([56, 78, 32], index=['a', 'b', ... Read More

How can a column of a dataframe be deleted in Python?

AmitDiwan
Updated on 10-Dec-2020 12:58:09

128 Views

Dataframe is a two dimensional data structure, where data is stored in a tabular format, in the form of rows and columns.It can be visualized as an SQL data table or an excel sheet representation. A column in a dataframe can be deleted using different methods.We will see the ‘del’ operator that takes the name of the column that needs to be deleted as a parameter, and deletes it −Example Live Demoimport pandas as pd my_data = {'ab' : pd.Series([1, 8, 7], index=['a', 'b', 'c']), 'cd' : pd.Series([1, 2, 0, 9], index=['a', 'b', 'c', 'd']), 'ef' : pd.Series([56, 78, 32], index=['a', ... Read More

How can a dataframe be created using a dictionary of Series in Python?

AmitDiwan
Updated on 10-Dec-2020 12:56:38

3K+ Views

Dataframe is a two dimensional data structure, where data is stored in a tabular format, in the form of rows and columns.It can be visualized as an SQL data table or an excel sheet representation. It can be created using the following constructor −pd.Dataframe(data, index, columns, dtype, copy)Let us understand how a dataframe can be created using a dictionary of Series.Series is a one dimensional data structure present in the ‘Pandas’ library.The axis label is collectively known as index.Series structure can store any type of data such as integer, float, string, python objects, and so on.Let us see an example ... Read More

How can a new column be added to an existing dataframe in Python?

AmitDiwan
Updated on 10-Dec-2020 12:55:27

281 Views

Dataframe is a two dimensional data structure, where data is stored in a tabular format, in the form of rows and columns.It can be visualized as an SQL data table or an excel sheet representation. It can be created using the following constructor −pd.Dataframe(data, index, columns, dtype, copy)A new column can be added to a dataframe in different ways.Let us see one of the ways, in which a new column is created by first forming a series data structure and passing this as an additional column to the existing dataframe.Let us see the code in action −Example Live Demoimport pandas as ... Read More

Advertisements