Search code examples
pythondigits

Extract digits from a cell calue on a data frame


i have a row in a data frame with this format: "19023"

I want to take of each cell in the row, the center value, in that case "02", the third and the fourth digits.

If it is easier, another posibility is to separe te numbers in independient values: "1" "9" "0" "2" "3", but i don't know how to implement these options...

its Python. I am trying to use datetime functions, because is: 2 digits for year, 2 digist for week, 1 digit for day:

data['DATE']=pd.to_datetime('DATE',format='%y%W%-d')

but gives error

Thanks u for all


Solution

  • if you are only interested in these two digits and not a date format then you could do something like data['date2'] = data['date'].apply(lamba x : x[2:4]). This will return a string but if you are interested in the date as a dateformat then you should convert it to datetime as you mentioned