Skip to content

Tag: python

split the string in dataframe in python

I have a data-frame and one of its columns are a string which separated with dash. I want to get the part before the dash. Could you help me with that? The desire output is: Answer You could use str.replace to remove the – and all characters after it: Output:

How do I format a date and also pad it with spaces?

Formatting appears to work differently if the object you’re formatting is a date. returns i.e. it has the padding. If I now do this: then the response is Which is obviously not what I want. I’ve tried various other combinations where I put in the date format as well, but all it does is draw the da…