Plenty of retailers are struggling, with sales and profits driven down by the continued rise of e-commerce. Some are trying to adapt, aiming to become omnichannel retailers able to compete on price and convenience with Amazon.com. Others are dragging their feet, unwilling or unable to invest in growing their own e-commerce businesses.

Image source: Getty Images.

The retail business is fundamentally changing, and the weakest operators will likely have trouble staying in business in the coming years. But that doesn't mean that there aren't some great retail stocks worthy of your investment dollars. Here's why Best Buy (BBY 0.13%) and Wal-Mart (WMT 0.59%) are two retail stocks to buy.

Winning market share

Best Buy wasn't in great shape a few years ago, but the company has since completely turned itself around. Despite industrywide declines in consumer electronics sales, Best Buy has been growing comparable sales, picking up market share from smaller rivals. Profits are soaring, with non-GAAP EPS up 51% year over year during the third quarter. And Best Buy has proven itself as a force to be reckoned with in e-commerce, with online sales growing at a double-digit pace.

Best Buy has succeeded over the past few years by becoming more price competitive, improving training for its employees, slashing unnecessary costs, and investing in e-commerce initiatives. The company's ship-from-store program, where online orders are shipped directly from stores, has sped up shipping times and improved merchandise availability.

Image source: Best Buy.

While Amazon is aggressively building out distribution centers around the country, Best Buy was able to effectively flip a switch and have more than 1,000 mini-distribution centers ready to serve its online customers. Best Buy's store base has became a major asset, helping the company drive e-commerce sales higher.

Analysts are expecting adjusted EPS of $3.28 this year, putting Best Buy's price-to-earnings ratio at about 13.5. That's already an attractive valuation, but the P/E ratio drops to less than 12 if the net cash on Best Buy's balance sheet is backed out. With the company proving that it's able to compete with Amazon while growing its profits, Best Buy is a great retail stock to own.

Being aggressive

Wal-Mart can no longer ignore Amazon. That's why the company has embarked on an ambitious plan to both make its stores more attractive to shoppers and dramatically increase its e-commerce capabilities. Higher wages and better training for employees, while painful for investors focused on the bottom line, have helped Wal-Mart's U.S. stores post nine consecutive quarters of comparable-sales growth. For a company the size of Wal-Mart, that's no small feat.

Wal-Mart's e-commerce business is also growing, with global sales growing by 20.6% year over year during the third quarter. The company is pushing its online grocery service, where customers order online and pick up at a Wal-Mart store, in an effort to maintain, and perhaps grow, its share of the grocery market. Wal-Mart is even testing out a new convenience store concept that allows customers to pick up their grocery orders without the inconvenience of traveling to one of the company's cavernous supercenters.

Image source: Wal-Mart.

Beyond groceries, the $3.3 billion acquisition of e-commerce start-up Jet.com shows that Wal-Mart is dead serious about competing with Amazon. Jet gives Wal-Mart a brand that appeals to younger shoppers, and its smart basket technology, which gives shoppers discounts based on how much they add to their cart, will be integrated into Walmart.com.

Wal-Mart expects to produce adjusted EPS between $4.20 and $4.35 this year, with profitability knocked down by the company's investments. This guidance puts the PE ratio at around 16. While not an obvious bargain, Wal-Mart has the potential to grow earnings substantially if its bet on e-commerce pays off. The company's new found aggressiveness when it comes to e-commerce is a good reason to bet on the stock.