
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Found 10476 Articles for Python

2K+ Views
We can create a Pivot Table with multiple columns. To create a Pivot Table, use the pandas.pivot_table to create a spreadsheet-style pivot table as a DataFrame.At first, import the required library −import pandas as pdCreate a DataFrame with Team records −dataFrame = pd.DataFrame({'Team ID': {0: 5, 1: 9, 2: 6, 3: 11, 4: 2, 5: 7 }, 'Team Name': {0: 'India', 1: 'Australia', 2: 'Bangladesh', 3: 'South Africa', 4: 'Sri Lanka', 5: 'England'}, 'Team Points': {0: 95, 1: 93, 2: 42, 3: 60, 4: 80, 5: 55}, 'Team Rank': {0: 'One', 1: 'Two', 2: 'Six', 3: 'Four', 4: 'Three', 5: ... Read More

561 Views
To get the minimum of column values, use the min() function. At first, import the required Pandas library −import pandas as pdNow, create a DataFrame with two columns −dataFrame1 = pd.DataFrame( { "Car": ['BMW', 'Lexus', 'Audi', 'Tesla', 'Bentley', 'Jaguar'], "Units": [100, 150, 110, 80, 110, 90] } )Finding the minimum value of a single column “Units” using min() −print"Minimum Units from DataFrame1 = ", dataFrame1['Units'].min() In the same way, we have calculated the minimum value from the 2nd DataFrame.ExampleFollowing is the complete code −import pandas as pd # Create DataFrame1 dataFrame1 = pd.DataFrame( { ... Read More

4K+ Views
To draw a curve connecting two points instead of a straight line in matplotlib, we can take the following steps −Set the figure size and adjust the padding between and around the subplots.Define a draw_curve() method to make a curve with a mathematical expression.Plot point1 and point2 data points.Plot x and y data points returned from the draw_curve() method.To display the figure, use show() method.Exampleimport matplotlib.pyplot as plt import numpy as np plt.rcParams["figure.figsize"] = [7.00, 3.50] plt.rcParams["figure.autolayout"] = True def draw_curve(p1, p2): a = (p2[1] - p1[1]) / (np.cosh(p2[0]) - np.cosh(p1[0])) b ... Read More

5K+ Views
To plot data from .txt file using matplotlib, we can take the following steps −Set the figure size and adjust the padding between and around the subplots.Initialize empty lists for bar_names and bar_heights.Open a sample .txt file in read "r" mode and append to bar's name and height list.Make a bar plot.To display the figure, use show() method.Examplefrom matplotlib import pyplot as plt plt.rcParams["figure.figsize"] = [7.00, 3.50] plt.rcParams["figure.autolayout"] = True bar_names = [] bar_heights = [] for line in open("test_data.txt", "r"): bar_name, bar_height = line.split() bar_names.append(bar_name) bar_heights.append(bar_height) plt.bar(bar_names, bar_heights) plt.show()"test_data.txt" contains the following data −Javed ... Read More

7K+ Views
When working with data visualization, plotting and saving a histogram on a local machine is a common task. This can be done using various functions provided by Python's Matplotlib, such as plt.savefig() and plt.hist(). The plt.hist is used function to create a histogram, by taking a list of data points. After the histogram is plotted we can save it, by using the plt.savefig() function. Steps to Plot, Save and Display a Histogram The steps included to plot and save the histogram are as follows. Configure ... Read More

1K+ Views
We can use pandas.DataFrame.corr to compute pairwise correlation of columns, excluding NULL values. The correlation coefficient indicates the strength of the linear association between two variables. The coefficient ranges between -1 and 1.To get the correlation between two numeric columns in a Pandas dataframe, we can take the following steps −Set the figure size and adjust the padding between and around the subplots.Create a Pandas dataframe of two-dimensional, size-mutable, potentially heterogeneous tabular data.Compare the values of the two columns and compute the correlation coefficient using col1.corr(col2).Print the correlation coefficient on the console.To display the figure, use show() method.Exampleimport pandas as ... Read More

826 Views
The Finite Element Method (FEM) is used in a variety of tasks such as modeling of different material types, testing complex geometries, visualizing the local effects acting on a small area of a design. It basically breaks a large spatial domain into simple parts called "finite elements". The simple equations that model these finite elements are then collected into a larger system of equations to model the entire domain.To plot 2d FEM results using matplotlib, we can take the following steps −Set the figure size and adjust the padding between and around the subplots.Create nodes, elements and node values data ... Read More

2K+ Views
To add a legend with vertical line in matplotlib, we can take the following steps −Set the figure size and adjust the padding between and around the subplots.Create a figure and a set of subplots.Plot the vertical line with red color.The line can have both a solid linestyle connecting all the vertices, and a marker at each vertex.Place a legend on the plot with vertical line.To display the figure, use show() method.Exampleimport matplotlib.pyplot as plt from matplotlib import lines plt.rcParams["figure.figsize"] = [7.00, 3.50] plt.rcParams["figure.autolayout"] = True fig, ax = plt.subplots() color = 'red' ax.plot([0, 0], [0, 3], ... Read More

4K+ Views
To exponentially scale the Y-axis with matplotlib, we can take the following steps −Set the figure size and adjust the padding between and around the subplots.Inintialize a variable dt for steps.Create x and y data points using numpy.Plot the x and y data points using numpy.Set the exponential scale for the Y-axis, using plt.yscale('symlog').To display the figure, use show() method.Exampleimport numpy as np import matplotlib.pyplot as plt plt.rcParams["figure.figsize"] = [7.00, 3.50] plt.rcParams["figure.autolayout"] = True dt = 0.01 x = np.arange(-50.0, 50.0, dt) y = np.arange(0, 100.0, dt) plt.plot(x, y) plt.yscale('symlog') plt.show()OutputIt will produce the following ... Read More

511 Views
To annotate Seaborn pairplots, we can use the fig.text() method.StepsImport Seaborn, Pandas, Numpy, and Pyplot packages.Set the figure size and adjust the padding between and around the subplots.Create a Pandas dataframe of two-dimensional, size-mutable, potentially heterogeneous tabular data.Plot pairwise relationships in a dataset, using sns.pairplot().Add an annotated text using fig.text() method.To display the figure, use show() method.Exampleimport seaborn as sns import pandas as pd import numpy as np import matplotlib.pyplot as plt plt.rcParams["figure.figsize"] = [7.00, 3.50] plt.rcParams["figure.autolayout"] = True df = pd.DataFrame( np.random.random((4, 4)), columns=["a", "b", "c", "d"] ) pp = ... Read More