#Create a function to split the values
def splitter(ratio):
try: #Try to split the values
return ratio.split(" : ")[0], ratio.split(" : ")[1]
except AttributeError: #return None for NaN's
return None, None
#apply the function to the column
df.loc[:, 'MaleNumerator'], df.loc[:, 'FemaleDenominator'] = zip(*df.male_female_Ratio.apply(splitter))
我相信有一种更优雅的方法可以做到这一点;但是,这里有一个快速而肮脏的选项:
相关问题 更多 >
编程相关推荐