This is my dataframe where "Original" is what I have and "Target" is where I would like to straighten it approximately to:
df = pd.DataFrame({
'Original': [0, 6, 14, 23, 49, 100],
'Target': [0, 10, 25, 40, 65, 100],
'Linear': [0, 20, 40, 60, 80, 100]
})
df.plot()
How can I also define the degree of straightening, like Target is 45% straightened and Linear is 100% straightened (and Original 0% straightened)?
>Solution :
Interpolate between your original data and the linear data. Empirically, a weight of 0.475 gives a pretty close approximation.
import pandas as pd
from matplotlib import pyplot as plt
df = pd.DataFrame(
{
"Original": [0, 6, 14, 23, 49, 100],
"Target": [0, 10, 25, 40, 65, 100],
"Linear": [0, 20, 40, 60, 80, 100],
}
)
weight = 0.475
df[f"Weight_{weight}"] = df["Original"] * (1 - weight) + df["Linear"] * weight
df.plot()
plt.show()

