In general, we can derive the expression for the density of any substance as a function of temperature using the definition of thermal expansion.
$$\frac{\mathrm dV}{\mathrm dT}=\alpha V\tag1$$
By differentiating $\rho=m/V$, we can show that $\mathrm d\rho/\rho = -\mathrm dV/V$. So using this and equation $\text{(1)}$,
$$\frac{\mathrm d\rho}{\mathrm dT}=-\alpha V\tag2$$
Integrating this above expression and approximating the expression,
$$\rho = \rho^\circ\cdot\left(1-\alpha\Delta T\right)\tag3$$
where $\rho^\circ$ is the initial density at the initial temperature, $\alpha$ is the volumetric thermal expansion coefficient and $\Delta T$ is the temperature.
For water, $\alpha$ is typically $207\times10^{-6}\ \mathrm{K^{-1}}$ at $20\ \mathrm{^\circ C}$. Using this, we can observe how temperature affects the density of water.