It is narrated from Sayyiduna Abu Sa'id al-Khudri (may Allah be pleased with him) that he heard the Messenger of Allah (peace and blessings be upon him) say: "Do not keep company except with a believer, and let none eat your food except the righteous."
Hadith Referenceسنن دارمي / من كتاب الاطعمة / 2094
Khatabi said: What is meant by this hadith is the food of invitation (such as a wedding feast, etc.), not food of necessity. The meaning of the hadith is that you should not keep company with evildoers, nor associate or socialize with them, otherwise their habits will influence you. Therefore, keep away from them and seek the company of the pious and God-fearing people.
The company of the righteous makes you righteous, The company of the wicked makes you wicked.
And Allah knows best. There are also numerous other ahadith with this meaning narrated in the books of hadith.