Server Side Programming Articles - Page 1411 of 2650

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

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

338 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

137 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

293 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

Explain how a dataframe structure can be created using list of dictionary values in Python?

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

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.It can be created using the following constructor −pd.Dataframe(data, index, columns, dtype, copy)The ‘data’, ‘index’, ‘columns’, ‘dtype’ and ‘copy’ are not compulsory values.A list of dictionaries can be passed as input to the dataframe. The keys of dictionary are taken as column names by default. Let us see an example −Example Live Demoimport pandas as pd my_data = [{'ab' : 34}, {'mn' : 56}, { 'gh' : ... Read More

What happens if the specified index is not present in the series Python Pandas?

AmitDiwan
Updated on 10-Dec-2020 12:50:18

550 Views

When the index values are customized, they are accessed using series_name[‘index_value’]. The ‘index_value’ passed to series is tried to be matched to the original series. If it is found, that corresponding data is also displayed on the console.When the index that is tried to be accessed is not present in the series, it throws an error. It has been shown below.Example Live Demoimport pandas as pd my_data = [34, 56, 78, 90, 123, 45] my_index = ['ab', 'mn' ,'gh', 'kl', 'wq', 'az'] my_series = pd.Series(my_data, index = my_index) print("The series contains following elements") print(my_series) print("Accessing elements using customized index") print(my_series['mm'])OutputThe series ... Read More

How to retrieve multiple elements from a series when the index is customized Python?

AmitDiwan
Updated on 10-Dec-2020 12:48:51

1K+ Views

When the index values are customized, they are accessed using series_name[‘index_value’].The ‘index_value’ passed to series is tried to be matched to the original series. If it is found, that corresponding data is also displayed on the console.Let us see how multiple elements can be displayed.Example Live Demoimport pandas as pd my_data = [34, 56, 78, 90, 123, 45] my_index = ['ab', 'mn' ,'gh', 'kl', 'wq', 'az'] my_series = pd.Series(my_data, index = my_index) print("The series contains following elements") print(my_series) print("Accessing multiple elements using customized index") print(my_series[['mn', 'az', 'wq', 'ab']])OutputThe series contains following elements ab  34 mn  56 gh  78 kl  90 wq ... Read More

Explain how series data structure in Python can be created using scalar/constant values?

AmitDiwan
Updated on 10-Dec-2020 12:45:35

296 Views

Scalar or constant values are defined once, and they are repeated across all rows/entries of the series data structure. Following is an example −Example Live Demoimport pandas as pd my_index = ['ab', 'mn' ,'gh', 'kl'] my_series = pd.Series(7, index = my_index) print("This is series data structure created using scalar values and specifying index values") print(my_series)OutputThis is series data structure created using scalar values and specifying index values ab   7 mn   7 gh   7 kl   7 dtype: int64ExplanationThe required libraries are imported, and their alias are given so that it is easy to use them.A list of index ... Read More

How can Seaborn library be used to display a Scatter Plot in Python?

AmitDiwan
Updated on 10-Dec-2020 12:44:08

212 Views

Visualizing data is an important step since it helps understand what is going on in the data without actually looking at the numbers and performing complicated computations. Seaborn is a library that helps in visualizing data.Scatter plot shows the distribution of data as data points that are spread/scattered on the graph. It uses dots to represents values of a dataset, which are numeric in nature. The position of every dot on the horizontal and vertical axis denotes the value for a single data point.They help understand the relationship between two variables. Let us understand how this can be achieved using ... Read More

How can series be created using Numpy and passing index value explicitly in Python?

AmitDiwan
Updated on 10-Dec-2020 12:42:59

237 Views

Let us see how a series data structure can be created with the help of a Numpy array, and explicitly giving values for ‘index’.When no value is specified for index, default values beginning from 0 are assigned to values in the series.Following is an example −Example Live Demoimport pandas as pd import numpy as np my_data = np.array(['ab', 'bc', 'cd', 'de', 'ef', 'fg', 'gh', 'hi']) my_index = [3, 5, 7, 9, 11, 23, 45, 67] my_series = pd.Series(my_data, index = my_index) print("This is series data structure created using Numpy array and specifying index values") print(my_series)OutputThis is series data structure created using ... Read More

Advertisements