Q:

Python -- how to use sum function on column of list values without unintentional concatenation

I'm working on a python assignment whereby I need to analyze a yelp dataset. The following are the columns of the dataset:
Index(['business_id', 'name', 'address', 'city', 'state', 'postal_code',
   'latitude', 'longitude', 'stars', 'review_count', 'is_open',
   'categories', 'hours', 'attributes.RestaurantsTakeOut',
   'attributes.BusinessParking', 'attributes.Ambience',
   'attributes.RestaurantsDelivery', 'attributes.RestaurantsReservations',
   'attributes.BusinessAcceptsCreditCards',
   'attributes.RestaurantsPriceRange2',
   'attributes.RestaurantsGoodForGroups', 'attributes.DriveThru',
   'attributes.GoodForKids', 'attributes.GoodForMeal', 'attributes.HasTV',
   'attributes.OutdoorSeating', 'attributes.CoatCheck',
   'attributes.HappyHour', 'attributes.Smoking', 'attributes.WiFi',
   'attributes.RestaurantsTableService', 'attributes.Alcohol',
   'attributes.Caters', 'attributes.Music', 'attributes.BestNights',
   'attributes.WheelchairAccessible', 'attributes.BusinessAcceptsBitcoin',
   'attributes.GoodForDancing', 'attributes.BikeParking',
   'attributes.RestaurantsAttire', 'attributes.NoiseLevel',
   'hours.Wednesday', 'hours.Thursday', 'hours.Friday', 'hours.Saturday',
   'hours.Sunday', 'hours.Monday', 'hours.Tuesday',
   'attributes.DogsAllowed', 'attributes.BYOBCorkage',
   'attributes.Corkage', 'attributes.BYOB', 'attributes.ByAppointmentOnly',
   'attributes.AgesAllowed', 'attributes.Open24Hours',
   'attributes.AcceptsInsurance'],
  dtype='object')

The following is one example of an entry from the dataset:
example of entry in dataset
I'm interested in the categories column. Each categories value is comprised of a list. In the example entry, that value is "Sandwiches, Salad, Restaurants, Burgers, Comfort Food". The next value in the "categories" column is "Nightlife, Bars, Polish, Modern European, Restaurants, Vegan". I want to aggregate all the values from the categories column for all the rows into a giant list. Ideally, this list would thus be an uninterrupted repository. For the first two rows, then, it would look like this:
"Sandwiches, Salad, Restaurants, Burgers, Comfort Food, Nightlife, Bars, Polish, Modern European, Restaurants, Vegan". 
I want to do this for all the rows. I used the following code:
all_labels = df.categories.sum()

Do let me know if this code is suboptimal and hopefully suggest something better. 
Anyways, when I print(all_labels), I run into a problem. This is what the aggregation of the first two rows looks like:
Sandwiches, Salad, Restaurants, Burgers, Comfort FoodNightlife, Bars, Polish, Modern European, Restaurants, Vegan

As you can see, concatenation has occurred where the first value ends and the next value begins (last item of first list merges with first item of second list). This is completely messing up my code as I run each category through another function -- specifically to find out how many rows contain each category. 
Can someone provide a solution to prevent this concatenation of words? 
Thanks in advance!

A:

I think that what you meant to use was join() instead of sum(), since you are concatenating strings that represent lists separated by commas, but each list does not end in a comma.
What about trying?
all_labels = ', '.join(df.categories)

This would insert commas between the strings you are joining (while sum() would concatenate the strings as they come).
We need more code to see what variable type you are trying to join, but if df.categories is comprised of strings, the line of code above might help to get you in the right direction.

