Python Forum
Split Column Text by Number of Characters
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Split Column Text by Number of Characters
#4
Just because it can be done: based on snippsat code one can develop following dense and 'nice' code:

>>> from datetime import datetime
>>> values = '201801,201802,201803'
>>> [datetime.strptime(f'{el[4:]}-{el[:4]}', '%m-%Y') for el in values.split(',')]
[datetime.datetime(2018, 1, 1, 0, 0),
 datetime.datetime(2018, 2, 1, 0, 0),
 datetime.datetime(2018, 3, 1, 0, 0)]
>>> [(date.month, date.year) for date in [datetime.strptime(f'{el[4:]}-{el[:4]}', '%m-%Y') for el in values.split(',')]]
[(1, 2018), (2, 2018), (3, 2018)]
I'm not 'in'-sane. Indeed, I am so far 'out' of sane that you appear a tiny blip on the distant coast of sanity. Bucky Katt, Get Fuzzy

Da Bishop: There's a dead bishop on the landing. I don't know who keeps bringing them in here. ....but society is to blame.
Reply


Messages In This Thread
RE: Split Column Text by Number of Characters - by perfringo - Mar-11-2019, 01:45 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
Brick Number stored as text with openpyxl CAD79 2 508 Apr-17-2024, 10:17 AM
Last Post: CAD79
  doing string split with 2 or more split characters Skaperen 22 2,607 Aug-13-2023, 01:57 AM
Last Post: Skaperen
Sad How to split a String from Text Input into 40 char chunks? lastyle 7 1,197 Aug-01-2023, 09:36 AM
Last Post: Pedroski55
  How to remove patterns of characters from text aaander 4 1,161 Nov-19-2022, 03:34 PM
Last Post: snippsat
  Two text files, want to add a column value zxcv101 8 1,971 Jun-20-2022, 03:06 PM
Last Post: deanhystad
  Split a number to list and list sum must be number sunny9495 5 2,342 Apr-28-2022, 09:32 AM
Last Post: Dexty
  How to split file by same values from column from imported CSV file? Paqqno 5 2,851 Mar-24-2022, 05:25 PM
Last Post: Paqqno
  Find if chain of characters or number Frankduc 4 1,822 Feb-11-2022, 01:55 PM
Last Post: Frankduc
  Search text in PDF and output its page number. atomxkai 21 9,114 Jan-21-2022, 06:20 AM
Last Post: snippsat
  Split single column to multiple columns SriRajesh 1 1,355 Jan-07-2022, 06:43 PM
Last Post: jefsummers

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020