Я хочу применить свою собственную функцию ecdf к каждому столбцу в кадре данных, а затем построить ecdf на основе возвращенных значений x, y
пользовательской функции:
def ecdf(df):
n = len(df)
x = np.sort(df)
y = np.arange(1, n+1)/n
return x, y
myпопытка цикла for:
for col in sj_interpol_data.columns:
x_col, y_col = ecdf(col)
ax = plt.figure()
ax = plt.plot(x_col, y_col, marker='.', linestyle='none')
ax = plt.margins=(0.02)
plt.show()
Отредактировано, чтобы включить ошибку:
AxisError Traceback (most recent call last)
<ipython-input-75-d03c4fa0a973> in <module>()
2 #design a for-loop which applies ecdf() on each column in df and plots them separately
3 for col in sj_interpol_data.columns:
----> 4 x_col, y_col = ecdf(col)
5 ax = plt.figure()
6 ax = plt.plot(x_col, y_col, marker='.', linestyle='none')
<ipython-input-32-353fb281e367> in ecdf(df)
4 n = len(df)
5 #define x values - sorted values in array
----> 6 x = np.sort(df)
7 #define y values - maps location of each datapoint WR to their percentiles
8 y = np.arange(1, n+1)/n
C:\Anaconda3\lib\site-packages\numpy\core\fromnumeric.py in sort(a, axis, kind, order)
845 else:
846 a = asanyarray(a).copy(order="K")
--> 847 a.sort(axis=axis, kind=kind, order=order)
848 return a
849
AxisError: axis -1 is out of bounds for array of dimension 0
Любой совет о том, как написать эту функцию, чтобы ее можно было применять ко всем столбцам в кадре данных и автоматическиучасток в цикле?