0

I have a dataframe which I drawed as you can see the figure and codes below;


import pandas as pd
from matplotlib import pyplot as plt

import numpy as np

df = pd.read_excel('nötronn.xlsx')


fig, ax = plt.subplots(figsize=(20,40))

ax1 = plt.subplot2grid((1,5), (0,0), rowspan=1, colspan = 1)
ax1.plot(df["N/F*10"], df['Depth'], color = "green", linewidth = 0.5)
ax1.set_xlabel("Porosity")
ax1.xaxis.label.set_color("green")
ax1.set_xlim(10, 50)
ax1.set_ylabel("Depth (m)")
ax1.tick_params(axis='x', colors="green")
ax1.spines["top"].set_edgecolor("green")
ax1.title.set_color('green')
ax1.set_xticks([10, 20, 30, 40, 50])

Output

I want to filter data so that I can realize the differences better. I tried these:

z = np.polyfit(df["N/F*10"], df['Depth'], 2)
p = np.poly1d(z)

plt.plot(df["N/F*10"], p(df["N/F*10"]))

But it gives :LinAlgError: SVD did not converge in Linear Least Squares

How can I solve it? Thanks.

Output expectation:

Output Expectation

gforce
  • 49
  • 7
  • Does this answer your question? [How to filter/smooth with SciPy/Numpy?](https://stackoverflow.com/questions/28536191/how-to-filter-smooth-with-scipy-numpy) – tevemadar May 09 '22 at 08:30
  • I want it to be same but I couldnt entegrated those codes into my dataframe – gforce May 09 '22 at 10:06

1 Answers1

0

This works!

import pandas as pd
from matplotlib import pyplot as plt
import numpy as np
from statsmodels.nonparametric.smoothers_lowess import lowess

data = pd.read_excel('nötronn.xlsx')

sub_data = data[data['Depth'] > 21.5]
result = lowess(sub_data['Eksi'], sub_data['Depth'].values)
x_smooth = result[:,0]
y_smooth = result[:,1]

tot_result = lowess(data['Eksi'], data['Depth'].values, frac=0.01)
x_tot_smooth = tot_result[:,0]
y_tot_smooth = tot_result[:,1]

fig, ax = plt.subplots(figsize=(20, 8))
##ax.plot(data.depth.values, data['N/F*10'], label="raw")
ax.plot(x_tot_smooth, y_tot_smooth, label="lowess 1%", linewidth=3, color="g")
ax.plot(data['GR-V121B-ETi'])
ax.plot(data['Caliper'], linestyle = 'dashed')
gforce
  • 49
  • 7