You want to know what $$\hat p\psi (x)$$ is. In In matrix algebra it's $$\left\langle x \right|\hat p\left| \psi \right\rangle $$ in x representation. In $$\left\langle x \right|\hat p\left| \psi \right\rangle $$ In wave mechanics it's $$\hat p\psi (x) = {\hbar \over i}{\partial \over {\partial x}}\psi (x) = {\hbar \over i}{\partial \over {\partial x}}\left\langle {x} \mathrel{\left | {\vphantom {x \psi }} \right.} {\psi } \right\rangle $$ . They $$ \hat p\psi (x) = {\hbar \over i}{\partial \over {\partial x}}\psi (x) = {\hbar \over i}{\partial \over {\partial x}}\left\langle {x} \mathrel{\left | {\vphantom {x \psi }} \right.} {\psi } \right\rangle \, . $$ They should be equal so that $$\langle x|\hat p\left| \psi \right\rangle = {\hbar \over i}{\partial \over {\partial x}}\left\langle {x} \mathrel{\left | {\vphantom {x \psi }} \right.} {\psi } \right\rangle $$. Although$$ \langle x|\hat p\left| \psi \right\rangle = {\hbar \over i}{\partial \over {\partial x}}\left\langle {x} \mathrel{\left | {\vphantom {x \psi }} \right.} {\psi } \right\rangle \, . $$
\begin{align} P \psi(x) &= \langle x | P | \psi \rangle \\ &= \int \langle x | P x' \rangle \langle x' | \psi \rangle \, dx \\ &= i \hbar \int \delta'(x' - x) \psi(x') \, dx' \\ &= -i \hbar \left.\frac{\partial \psi(x')}{\partial x'} \right \rvert_{x'=x} \\ &= -i \hbar \frac{\partial \psi(x)}{\partial x} \end{align}
Although I always forget the derivation in the picturequote box above I remember they should be euqalequal.