Playing piano by ear is an excellent skill to have. I'm sure you've seen people who can do it well. They can sit down and play anything they hear.
Some people have a talent for playing by ear but it is also a skill that can be learned. I have found that the more I practice it the better I get.
You can start to learn on your own or use a guide. If you're a beginner, I would suggest looking at the resources I list below. Learning music is a bit like learning another language and there are specific terms you'll find thrown around that can make it all seem overwhelming.
If you haven't learned chords, I would recommend doing that before you start playing piano by ear. Chords make it much easier to play by ear.
This is the process I would recommend for improving your ear:
1. Pick an easy song to work on.
2. Listen for the bass line of the song and try to play it.
3. With the bass line, start working out the chords.
4. Start figuring out the melody. Most of the melody notes will be a part of the chord in that area.
5. To improve playing a melody, do some ear training. You can find some free ear training with this Online Ear Trainer. It is not really for beginners but you can combine the terms with Youtube videos to figure it out.
Ear training is learning about a number of things:
Intervals: these are the spaces between 2 notes and are called by particular names. (This helps you learn to play a melody by ear.)
Chords: you learn whether chords are major, minor, 7th, etc. You also learn about which notes of the chord are at the top, middle and bottom. (This helps you to play an accompaniment by ear.)
Scales: you learn which type of scale is being played.
I have recommended a number of piano courses for playing by ear over the years but they just haven't stood the test of time.
What I do recommend is either of these course books. Both are well-regarded and popular. The first is better for beginners.
This is the more expensive option of the two here but those who have bought it, love it. It is also the best option for beginner piano players.
You can use it on its own or purchase the video course from Udemy to go along with it. (Udemy courses often go on sale for $15 so maybe you can score a deal there.)
Highlights of this course:
This is also a great book for those learning to play by ear. If you are a beginner, or even an advanced beginner, it may be too technical for you.
For those who already know a bit about piano, you'll find it useful.
Overall, playing piano by ear well and fluently comes with practice. The more you'll do it, the better you'll get.