The discounter Walmart has attracted more high-income households because of inflation and investments in its stores and website.