Extracting parts of a string based on substrings in a dataframe – python

  dataframe, pandas, partition, python, strip

I am trying to extract some NBA data, but my dataframe has a column where all of the statistics are in one string separated by spaces in a Stats column as shown: eg. 29pt 15rb 3as 1bl …etc. I want to extract the values of each statistic so that I have a column for points, rebounds, assist, blocks, etc. The issue I am running into is some rows might not contain every statistic. For example, if a player did not get any assists, their value in the Stats column could look like this: 14pt 3rb 2bl. I am having trouble extracting the values I need for each statistic, especially if the statistic doesn’t exist for that player. I have tried to split the string so that its values are placed into a list, and this was promising, but I still cannot figure out how to get the values for each statistic if that statistic even exists for that player. Any recommendations, ideas, or guidance would be greatly appreciated. Thanks.


Source: Python Questions