title: Separate comma-separated values within individual cells of Pandas Series using regex
body: <p>I have a csv file from a database I've converted into a Pandas DataFrame that I'm trying to clean up. One of the issues is that multiple values have been input into single cells that need to be split up. The complicating factor is that there are string comments (also with commas) that need to be kept intact. The problem is illustrated in the example below, in Series form.</p>
  
  <p>What I have:</p>
  
  <pre><code>Index  |  values    
  0      | 2.54,3.563
  1      | bad design, right?
  </code></pre>
  
  <p>What I want:</p>
  
  <pre><code>Index  |   level_0   |  values      
  0      |     0       |    2.54   
  1      |     0       |    3.563 
  2      |     1       |    bad design, right?      
  </code></pre>
  
  <p>As you can see, there are commas separating the values I want to split, with no following space after the comma, while the commas in string comments all have spaces after them. Seems like an easy thing to apply regex to split up. My solution below, using a strategy taken from another StackOverflow solution, is to use Series.str.split to separate the values into separate columns, then stack the columns. That strategy works great. However, in this case, the regex is apparently not identifying the split. Here's my code:</p>
  
  <pre><code>Import pandas as pd
  
  # Example Series:
  data = pd.Series(("2.54,3.56", "3.24,5.864", "bad design, right?"), name = "values")
  
  # Split cells with multiple entries into separate rows 
  split_data = data.str.split('[,]\b').apply(pd.Series)
  
  # Stack the results and pull out the index into a column (which is sample number in my case)
  split_data = split_data.stack().reset_index(0)
  split_data = split_data.reset_index(drop=True)
  </code></pre>
  
  <p>I'm new to regular expressions, but from the guides I've looked at and from using a couple regex sandboxes specific to Python, it seems like the regex [,]\b  should split the values, but not the comments. However, it does not split anything with this regex.</p>
  
  <p>Here's the result of the debugger, which says this should work:
  <a href="https://www.debuggex.com/r/UwTVnYS7GRSkAKJL" rel="nofollow">Debuggex Demo</a></p>
  
  <p>Am I missing something easy here? Any better ideas on making this work? I'm using Python 3.5, if that makes a difference. Thanks.</p>