Delete a Record from a Table Using MySQL in Python

Pawandeep Kaur
Updated on 10-Jun-2021 12:37:21

471 Views

We may at times need to delete certain rows from a table. Suppose, we have a table of details of students in the class. It is possible that one of the students left the class and hence, we do not require the details of that particular student. Hence, we need to delete that particular row or record from the table.The “DELETE FROM” statement in MySQL is used to delete a row or record from the table, The “WHERE” clause is used to specify the row to be deleted. If WHERE clause is not used, then all the records will be ... Read More

Order Result of SELECT Query in MySQL

Pawandeep Kaur
Updated on 10-Jun-2021 12:26:46

753 Views

It is common to select certain data or rows from a table. The rows are returned in the order in which they appear in the table. We may sometimes require that the rows we select from the table must be returned to us in ascending or descending order with respect to some column.The “ORDER BY” statement is used to order the results with respect to some column. The following example will provide more clarity.Suppose, we have a table which consists of various fields including the “name” field. We want to select all the rows from the table but we want ... Read More

Select Data from a Table Using MySQL in Python

Pawandeep Kaur
Updated on 10-Jun-2021 12:18:26

791 Views

It is not frequently required to select all the data from the table. Instead , we need to select data or rows from the table based on some condition or criteria.Suppose, we have a table which includes names and marks of many students. Now, we need to get names of the students whose marks are above 90. This basically requires us to select data based on some criteria ,which is(marks>=90).Therefore, we are provided with “WHERE” statement in MySQL which allows us to select data from the table based on some specified criteria.SyntaxSELECT * FROM table_name WHERE conditionHere, table_name specifies the ... Read More

Plot Scatter Masked Points and Add Line in Matplotlib

Rishikesh Kumar Rishi
Updated on 10-Jun-2021 12:16:29

433 Views

To plot scattered masked points and add a line to demark the masked regions, we can take the following steps.StepsSet the figure size and adjust the padding between and around the subplots.Create N, r0, x, y, area, c, r, area1and area2 data points using numpy.Plot x and y data points using scatter() method.To demark the maked regions, plot the curve using plot() method.To display the figure, use show() method.Exampleimport matplotlib.pyplot as plt import numpy as np plt.rcParams["figure.figsize"] = [7.50, 3.50] plt.rcParams["figure.autolayout"] = True N = 100 r0 = 0.6 x = 0.9 * np.random.rand(N) y = 0.9 * ... Read More

Move Labels from Bottom to Top in Matplotlib

Rishikesh Kumar Rishi
Updated on 10-Jun-2021 12:16:03

789 Views

To move labels from bottom to top without adding ticks, we can take the following steps −Set the figure size and adjust the padding between and around the subplots.Create random data of 5☓5 dimension matrix.Display the data as an image, i.e., on a 2D regular raster using imshow() method.Use tick_params() method to move labels from bottom to top.To display the figure, use show() method.Exampleimport numpy as np from matplotlib import pyplot as plt plt.rcParams["figure.figsize"] = [7.50, 3.50] plt.rcParams["figure.autolayout"] = True data = np.random.rand(5, 5) plt.imshow(data, cmap="copper") plt.tick_params(axis='both', which='major',                labelsize=10, labelbottom=False, ... Read More

Plot Masked and NaN Values in Matplotlib

Rishikesh Kumar Rishi
Updated on 10-Jun-2021 12:15:39

4K+ Views

To plot masked and NaN values in Matplotlib, we can take the following steps −Set the figure size and adjust the padding between and around the subplots.Create x and y data points using numpy.Get x2 and y2 data points such that y > 0.7.Get masked y3 data points such that y > 0.7.Mask y3 with NaN values.Plot x, y, y2, y3 and y4 using plot() method.Place a legend to the plot.Set the title of the plot.To display the figure, use show() method.Exampleimport matplotlib.pyplot as plt import numpy as np plt.rcParams["figure.figsize"] = [7.50, 3.50] plt.rcParams["figure.autolayout"] = True x = ... Read More

Zoom with Axes3D in Matplotlib

Rishikesh Kumar Rishi
Updated on 10-Jun-2021 12:14:51

2K+ Views

To zoom with Axes3D, we can take the following steps −Set the figure size and adjust the padding between and around the subplots.Create a new figure or activate an existing figure using figure() method.Get 3D axes object using Axes3D(fig) method.Plot x, y and z data points using scatter() method.To display the figure, use show() method.Examplefrom mpl_toolkits.mplot3d import Axes3D from matplotlib import pyplot as plt plt.rcParams["figure.figsize"] = [7.50, 3.50] plt.rcParams["figure.autolayout"] = True fig = plt.figure() ax = Axes3D(fig) x = [2, 4, 6, 3, 1] y = [1, 6, 8, 1, 3] z = [3, 4, 10, 3, 1] ... Read More

Get Alternating Colours in a Dashed Line using Matplotlib

Rishikesh Kumar Rishi
Updated on 10-Jun-2021 12:13:44

702 Views

To get alternating colors in a dashed line using Matplotlib, we can take the following steps −Set the figure size and adjust the padding between and around the subplotsGet the current axis.Create x and y data points using numpy.Plot x and y data points with "-" and "--" linestyle.To display the figure, use show() method.Examplefrom matplotlib import pyplot as plt import numpy as np plt.rcParams["figure.figsize"] = [7.50, 3.50] plt.rcParams["figure.autolayout"] = True ax = plt.gca() x = np.linspace(-10, 10, 100) y = np.sin(x) ax.plot(x, y, '-', color='red', linewidth=5) ax.plot(x, y, '--', color='yellow', linewidth=5) plt.show()OutputRead More

Capacitors in AC Circuits

Manish Kumar Saini
Updated on 10-Jun-2021 12:13:16

2K+ Views

Consider the circuit consisting of a capacitor (C) only. When an alternating voltage is applied across the capacitor, the capacitor being charged in one direction and then in the other as the voltage reverses. Due to the application of alternating voltage across the capacitor the electrons move to and fro around the circuit, thus constituting alternating current.Let the equation of the applied alternating voltage is$$\mathrm{u= V_{m} sin(\omega t)}\:\:\:….. (1)$$As a result of the alternating voltage (v), alternating current will flow through the circuit (i). Let at any instant q is the charge on plates of the capacitor. Thus, $$\mathrm{q=C u ... Read More

FetchOne Method in MySQL Python

Pawandeep Kaur
Updated on 10-Jun-2021 12:12:58

9K+ Views

Fetchone() methodFetchone() method is used when you want to select only the first row from the table. This method only returns the first row from the MySQL table.Use of fetchone() methodThe fetchone() is not used as a query to be used to the cursor object. The query passed is “SELECT *” which fetches all the rows from the table.Later , we operate fetchone() method on the result returned by “SELECT *”. The fetchone() method then fetches the first row from that result.Steps you need to follow to fetch first row from a table using MySQL in pythonimport MySQL connectorestablish connection ... Read More

Advertisements