I have a DataFrame that I wish to refine in a way that only the relevant data stays on top. The only way I figured out how to do it was by separating the data frame as I will also need to scatter plot it later and transforming it into two lists, passing them through a loop. This is not working out as PyCharm console always get stuck, not running the code untill the end or not returning the k as it was intended to. Please help me improve this code and make it work.
Here is the code:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
|
import pandas as pd from matplotlib import pyplot as plt df = pd.read_csv( "C:/Users/thech/OneDrive/Documents/Rocky/Workshop2A/200mm/DataXY/ExtractedCellsData/CurveE_RR0.csv" ) x = df.iloc[:, 0 ] y = df.iloc[:, 1 ] #plt.scatter(x, y) #plt.show(block=True) xmax = x.iloc[ - 1 ] ymax = y. max () xmin = x.iloc[ 0 ] ymin = y. min () tgbeta = 2 * (ymax - ymin) / (xmax - xmin) xl = x.to_list() yl = y.to_list() def refine_data(xn: list [ float ], yn: list [ float ], tangent: float ) - > int : k = 0 # number of deleted points/Cells for i in range ( len (yn)): # loop if abs (xn[i]) / yn[i] < 0.8 / tangent: yn[i] = yn[k] xn[i] = xn[k] k + = 1 return k refine_data(xl, yl, tgbeta) |
Please post all code, output and errors (it it’s entirety) between their respective tags. Refer to BBCode help topic on how to post. Use the “Preview Post” button to make sure the code is presented as you expect before hitting the “Post Reply/Thread” button.
Tags have been added tthis time. Please use BBCode tags on future posts.