Best way to strip punctuation from a string

From an efficiency perspective, you’re not going to beat For higher versions of Python use the following code: It’s performing raw string operations in C with a lookup table – there’s not much that will beat that but writing your own C code. If speed isn’t a worry, another option though is: This is faster … Read more

Pandas: ValueError: cannot convert float NaN to integer

For identifying NaN values use boolean indexing: Then for removing all non-numeric values use to_numeric with parameter errors=’coerce’ – to replace non-numeric values to NaNs: And for remove all rows with NaNs in column x use dropna: Last convert values to ints:

numpy array concatenate: “ValueError: all the input arrays must have same number of dimensions”

To use np.concatenate, we need to extend the second array to 2D and then concatenate along axis=1 – Alternatively, we can use np.column_stack that takes care of it – Sample run – If b is such that its a 1D array of dtype=object with a shape of (1,), most probably all of the data is contained in the only element in it, we need to flatten it out before concatenating. For … Read more