I am trying to figure out how to get x values based on y value from panda data series and matplolib.
To be more precise I need to get x value when y=0.5 from multiple columns. The data is normalized and cut according to user inputs.
I don't have enough data points to get precise 0.5 value (the nearest might be 0.4 or 0.6)
I though maybe it is possible to draw line at 0.5 value and get intersection points or somehow interpolate data, but I do not realy know how to do it properly.
Maybe someone has some suggestions?
import pandas as pd
import matplotlib.pyplot as plt
df = pd.read_csv('test.csv', header=0, sep=',' )
colnames = list(df.columns)
print(colnames)
colnames.pop(0)
for i in colnames:
df[i]= (df[i] - df[i].min()) / (df[i].max() - df[i].min())
print(df)
df.plot(x='Temperature')
plt.show()
y = input('Enter temperature')
d1 = df[df['Temperature'] >= int(y)]
a = input('Second temperature')
d2 = d1[d1['Temperature'] <= int(a)]
colnames2 = list(d2.columns)
for i in colnames2:
df[i] = (df[i] - df[i].min()) / (df[i].max() - df[i].min())
main = d2.plot(x='Temperature')
line = plt.axhline(y=0.5, color='black', linestyle='-')
plt.show()
p1 = d2.interpolate()