How to extract first 8 characters from a string in pandas

You are close, need indexing with str which is apply for each value of Series: data[‘Order_Date’] = data[‘Shipment ID’].str[:8] For better performance if no NaNs values: data[‘Order_Date’] = [x[:8] for x in data[‘Shipment ID’]] print (data) Shipment ID Order_Date 0 20180504-S-20000 20180504 1 20180514-S-20537 20180514 2 20180514-S-20541 20180514 3 20180514-S-20644 20180514 4 20180514-S-20644 20180514 5 … Read more

Find all locations of substring in NSString (not just first)

You can use rangeOfString:options:range: and set the third argument to be beyond the range of the first occurrence. For example, you can do something like this: NSRange searchRange = NSMakeRange(0,string.length); NSRange foundRange; while (searchRange.location < string.length) { searchRange.length = string.length-searchRange.location; foundRange = [string rangeOfString:substring options:0 range:searchRange]; if (foundRange.location != NSNotFound) { // found an occurrence … Read more