Sometimes bankrupt companies can be a good choice for an investor. The key is not to buy their stock while in bankruptcy, but rather to wait until their new stock is issued. A bankrupt company issues stock to raise money to pay back some of their debt. Often the biggest beneficiaries are their old creditors.
Large investors are paid back with large quantities of the company's new stock, but are reluctant to hold it due to their previous experience. They often sell it very quickly, driving down the value of the stock to below what it should be. This creates an opportunity for a small investor to pick those shares at a bargain price.
This is generally best done with companies that have a small market-cap. This is because bankruptcies create a kind of investor feeding frenzy where so called "vulture investors" do their best to acquire the company's remaining assets. A company that has been fed on may not be a good long term investment, and its low share price may be appropriate. Small cap companies represent less appetizing meals.
The key, as always, is due diligence in researching the companies remaining fundamental assets. Determine whether the company suffered a single catastrophic event that drove it into bankruptcy, or was fundamentally flawed and rotted from the inside. Find out if the problem that drove it into bankruptcy still exists, or the situation may repeat itself. Consider all of these things when deciding if their new stock is right for you.