Splitting and extracting values from a row?How to concatenate text from multiple rows into a single text string in SQL server?How do you split a list into evenly sized chunks?Extracting extension from filename in PythonHow do I sort a dictionary by value?How to access environment variable values?Use a list of values to select rows from a pandas dataframeDelete column from pandas DataFrame by column name“Large data” work flows using pandasHow to iterate over rows in a DataFrame in Pandas?Select rows from a DataFrame based on values in a column in pandas
Thesis' "Future Work" section – is it acceptable to omit personal involvement in a mentioned project?
Are there variations of the regular runtimes of the Big-O-Notation?
Can I do brevets (long distance rides) on my hybrid bike? If yes, how to start?
On what legal basis did the UK remove the 'European Union' from its passport?
How can a Lich look like a human without magic?
Why can't RGB or bicolour LEDs produce a decent yellow?
How do I tell my supervisor that he is choosing poor replacements for me while I am on maternity leave?
Limit of an integral vs Limit of the integrand
How do I compare the result of "1d20+x, with advantage" to "1d20+y, without advantage", assuming x < y?
Can you book a one-way ticket to the UK on a visa?
International Code of Ethics for order of co-authors in research papers
Is the schwa sound consistent?
Is a vertical stabiliser needed for straight line flight in a glider?
How could a Lich maintain the appearance of being alive without magic?
Remove everything except csv file Bash Script
What are some possible reasons that a father's name is missing from a birth certificate - England?
How can this pool heater gas line be disconnected?
Pre-1993 comic in which Wolverine's claws were turned to rubber?
Control variables and other independent variables
How are Core iX names like Core i5, i7 related to Haswell, Ivy Bridge?
Why do unstable nuclei form?
How to pronounce "r" after a "g"?
Was this a power play by Daenerys?
How do I get past a 3-year ban from overstay with VWP?
Splitting and extracting values from a row?
How to concatenate text from multiple rows into a single text string in SQL server?How do you split a list into evenly sized chunks?Extracting extension from filename in PythonHow do I sort a dictionary by value?How to access environment variable values?Use a list of values to select rows from a pandas dataframeDelete column from pandas DataFrame by column name“Large data” work flows using pandasHow to iterate over rows in a DataFrame in Pandas?Select rows from a DataFrame based on values in a column in pandas
.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty height:90px;width:728px;box-sizing:border-box;
From the following line, I want to extract the date and time including AM/PM.
But the time part of DateTime is skipped.
6/1/2018 12:01:11.490 AM HEP.U02.OIL.GOV.P2_RUN <Unit #2>No.2 oil pump runing On "
p=[]
xx = "6/1/2018 12:01:11.490 AM HEP.U02.OIL.GOV.P2_RUN <Unit #2>No.2
oil pump runing On "
new=re.split(r's',xx)
print(new)
p.append(new.pop(0))
p.append(new.pop(1))
print(p)
python pandas csv
add a comment |
From the following line, I want to extract the date and time including AM/PM.
But the time part of DateTime is skipped.
6/1/2018 12:01:11.490 AM HEP.U02.OIL.GOV.P2_RUN <Unit #2>No.2 oil pump runing On "
p=[]
xx = "6/1/2018 12:01:11.490 AM HEP.U02.OIL.GOV.P2_RUN <Unit #2>No.2
oil pump runing On "
new=re.split(r's',xx)
print(new)
p.append(new.pop(0))
p.append(new.pop(1))
print(p)
python pandas csv
add a comment |
From the following line, I want to extract the date and time including AM/PM.
But the time part of DateTime is skipped.
6/1/2018 12:01:11.490 AM HEP.U02.OIL.GOV.P2_RUN <Unit #2>No.2 oil pump runing On "
p=[]
xx = "6/1/2018 12:01:11.490 AM HEP.U02.OIL.GOV.P2_RUN <Unit #2>No.2
oil pump runing On "
new=re.split(r's',xx)
print(new)
p.append(new.pop(0))
p.append(new.pop(1))
print(p)
python pandas csv
From the following line, I want to extract the date and time including AM/PM.
But the time part of DateTime is skipped.
6/1/2018 12:01:11.490 AM HEP.U02.OIL.GOV.P2_RUN <Unit #2>No.2 oil pump runing On "
p=[]
xx = "6/1/2018 12:01:11.490 AM HEP.U02.OIL.GOV.P2_RUN <Unit #2>No.2
oil pump runing On "
new=re.split(r's',xx)
print(new)
p.append(new.pop(0))
p.append(new.pop(1))
print(p)
python pandas csv
python pandas csv
edited Mar 23 at 23:23
Anony-Mousse
59.8k798164
59.8k798164
asked Mar 23 at 11:06
imtiaz ul Hassanimtiaz ul Hassan
417
417
add a comment |
add a comment |
2 Answers
2
active
oldest
votes
No, time
part is there, pop
function is the problem, your regex is fine, as can be seen by running source code below (there is no need for pop
in this case tbh):
Simple solution (without pop
):
import re
xx = (
"6/1/2018 12:01:11.490 AM HEP.U02.OIL.GOV.P2_RUN <Unit #2>No.2 oil pump runing On"
)
new = re.split(r"s", xx)
print(new[:3])
Which returns as expected:
['6/1/2018', '12:01:11.490', 'AM']
Why it didn't work?
When you pop
element it is removed from the list. You remove 0
element ('6/1/2018'
), new 0
element became the missing date and afterwards you popped first element which is actually AM
.
With popping you would do that to get all three (assumming new
is already created as before):
for _ in range(3):
print(new.pop(0))
isn't there any other way I can retrieve those values without poping?
– imtiaz ul Hassan
Mar 23 at 11:37
1
Of course there is,updated my answer. It would work withpop
as well, though it's totally not needed here IMO.
– Szymon Maszke
Mar 23 at 11:39
add a comment |
I am not great at regex and there is certainly scope to tighten this regex up but as a first stab assuming your datetime strings have a fixed format. It does not validate the date.
import re
xx = "6/1/2018 12:01:11.490 AM HEP.U02.OIL.GOV.P2_RUN <Unit #2>No.2 oil pump runing On "
p1 = re.compile('(?:d1,2/)2d4s+(?:d2:)2d2.d3s+[AaPp][Mm]')
p = re.findall(p1, xx)
print(p)
You missed the actual problem with his code and created highly complex regex which does not work any better (only clutters the whole thing and makes it much less readable/understandable by others).
– Szymon Maszke
Mar 23 at 11:34
add a comment |
Your Answer
StackExchange.ifUsing("editor", function ()
StackExchange.using("externalEditor", function ()
StackExchange.using("snippets", function ()
StackExchange.snippets.init();
);
);
, "code-snippets");
StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "1"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);
else
createEditor();
);
function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);
);
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55313044%2fsplitting-and-extracting-values-from-a-row%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
2 Answers
2
active
oldest
votes
2 Answers
2
active
oldest
votes
active
oldest
votes
active
oldest
votes
No, time
part is there, pop
function is the problem, your regex is fine, as can be seen by running source code below (there is no need for pop
in this case tbh):
Simple solution (without pop
):
import re
xx = (
"6/1/2018 12:01:11.490 AM HEP.U02.OIL.GOV.P2_RUN <Unit #2>No.2 oil pump runing On"
)
new = re.split(r"s", xx)
print(new[:3])
Which returns as expected:
['6/1/2018', '12:01:11.490', 'AM']
Why it didn't work?
When you pop
element it is removed from the list. You remove 0
element ('6/1/2018'
), new 0
element became the missing date and afterwards you popped first element which is actually AM
.
With popping you would do that to get all three (assumming new
is already created as before):
for _ in range(3):
print(new.pop(0))
isn't there any other way I can retrieve those values without poping?
– imtiaz ul Hassan
Mar 23 at 11:37
1
Of course there is,updated my answer. It would work withpop
as well, though it's totally not needed here IMO.
– Szymon Maszke
Mar 23 at 11:39
add a comment |
No, time
part is there, pop
function is the problem, your regex is fine, as can be seen by running source code below (there is no need for pop
in this case tbh):
Simple solution (without pop
):
import re
xx = (
"6/1/2018 12:01:11.490 AM HEP.U02.OIL.GOV.P2_RUN <Unit #2>No.2 oil pump runing On"
)
new = re.split(r"s", xx)
print(new[:3])
Which returns as expected:
['6/1/2018', '12:01:11.490', 'AM']
Why it didn't work?
When you pop
element it is removed from the list. You remove 0
element ('6/1/2018'
), new 0
element became the missing date and afterwards you popped first element which is actually AM
.
With popping you would do that to get all three (assumming new
is already created as before):
for _ in range(3):
print(new.pop(0))
isn't there any other way I can retrieve those values without poping?
– imtiaz ul Hassan
Mar 23 at 11:37
1
Of course there is,updated my answer. It would work withpop
as well, though it's totally not needed here IMO.
– Szymon Maszke
Mar 23 at 11:39
add a comment |
No, time
part is there, pop
function is the problem, your regex is fine, as can be seen by running source code below (there is no need for pop
in this case tbh):
Simple solution (without pop
):
import re
xx = (
"6/1/2018 12:01:11.490 AM HEP.U02.OIL.GOV.P2_RUN <Unit #2>No.2 oil pump runing On"
)
new = re.split(r"s", xx)
print(new[:3])
Which returns as expected:
['6/1/2018', '12:01:11.490', 'AM']
Why it didn't work?
When you pop
element it is removed from the list. You remove 0
element ('6/1/2018'
), new 0
element became the missing date and afterwards you popped first element which is actually AM
.
With popping you would do that to get all three (assumming new
is already created as before):
for _ in range(3):
print(new.pop(0))
No, time
part is there, pop
function is the problem, your regex is fine, as can be seen by running source code below (there is no need for pop
in this case tbh):
Simple solution (without pop
):
import re
xx = (
"6/1/2018 12:01:11.490 AM HEP.U02.OIL.GOV.P2_RUN <Unit #2>No.2 oil pump runing On"
)
new = re.split(r"s", xx)
print(new[:3])
Which returns as expected:
['6/1/2018', '12:01:11.490', 'AM']
Why it didn't work?
When you pop
element it is removed from the list. You remove 0
element ('6/1/2018'
), new 0
element became the missing date and afterwards you popped first element which is actually AM
.
With popping you would do that to get all three (assumming new
is already created as before):
for _ in range(3):
print(new.pop(0))
edited Mar 23 at 11:38
answered Mar 23 at 11:32
Szymon MaszkeSzymon Maszke
3,1691729
3,1691729
isn't there any other way I can retrieve those values without poping?
– imtiaz ul Hassan
Mar 23 at 11:37
1
Of course there is,updated my answer. It would work withpop
as well, though it's totally not needed here IMO.
– Szymon Maszke
Mar 23 at 11:39
add a comment |
isn't there any other way I can retrieve those values without poping?
– imtiaz ul Hassan
Mar 23 at 11:37
1
Of course there is,updated my answer. It would work withpop
as well, though it's totally not needed here IMO.
– Szymon Maszke
Mar 23 at 11:39
isn't there any other way I can retrieve those values without poping?
– imtiaz ul Hassan
Mar 23 at 11:37
isn't there any other way I can retrieve those values without poping?
– imtiaz ul Hassan
Mar 23 at 11:37
1
1
Of course there is,updated my answer. It would work with
pop
as well, though it's totally not needed here IMO.– Szymon Maszke
Mar 23 at 11:39
Of course there is,updated my answer. It would work with
pop
as well, though it's totally not needed here IMO.– Szymon Maszke
Mar 23 at 11:39
add a comment |
I am not great at regex and there is certainly scope to tighten this regex up but as a first stab assuming your datetime strings have a fixed format. It does not validate the date.
import re
xx = "6/1/2018 12:01:11.490 AM HEP.U02.OIL.GOV.P2_RUN <Unit #2>No.2 oil pump runing On "
p1 = re.compile('(?:d1,2/)2d4s+(?:d2:)2d2.d3s+[AaPp][Mm]')
p = re.findall(p1, xx)
print(p)
You missed the actual problem with his code and created highly complex regex which does not work any better (only clutters the whole thing and makes it much less readable/understandable by others).
– Szymon Maszke
Mar 23 at 11:34
add a comment |
I am not great at regex and there is certainly scope to tighten this regex up but as a first stab assuming your datetime strings have a fixed format. It does not validate the date.
import re
xx = "6/1/2018 12:01:11.490 AM HEP.U02.OIL.GOV.P2_RUN <Unit #2>No.2 oil pump runing On "
p1 = re.compile('(?:d1,2/)2d4s+(?:d2:)2d2.d3s+[AaPp][Mm]')
p = re.findall(p1, xx)
print(p)
You missed the actual problem with his code and created highly complex regex which does not work any better (only clutters the whole thing and makes it much less readable/understandable by others).
– Szymon Maszke
Mar 23 at 11:34
add a comment |
I am not great at regex and there is certainly scope to tighten this regex up but as a first stab assuming your datetime strings have a fixed format. It does not validate the date.
import re
xx = "6/1/2018 12:01:11.490 AM HEP.U02.OIL.GOV.P2_RUN <Unit #2>No.2 oil pump runing On "
p1 = re.compile('(?:d1,2/)2d4s+(?:d2:)2d2.d3s+[AaPp][Mm]')
p = re.findall(p1, xx)
print(p)
I am not great at regex and there is certainly scope to tighten this regex up but as a first stab assuming your datetime strings have a fixed format. It does not validate the date.
import re
xx = "6/1/2018 12:01:11.490 AM HEP.U02.OIL.GOV.P2_RUN <Unit #2>No.2 oil pump runing On "
p1 = re.compile('(?:d1,2/)2d4s+(?:d2:)2d2.d3s+[AaPp][Mm]')
p = re.findall(p1, xx)
print(p)
answered Mar 23 at 11:28
QHarrQHarr
41.7k82447
41.7k82447
You missed the actual problem with his code and created highly complex regex which does not work any better (only clutters the whole thing and makes it much less readable/understandable by others).
– Szymon Maszke
Mar 23 at 11:34
add a comment |
You missed the actual problem with his code and created highly complex regex which does not work any better (only clutters the whole thing and makes it much less readable/understandable by others).
– Szymon Maszke
Mar 23 at 11:34
You missed the actual problem with his code and created highly complex regex which does not work any better (only clutters the whole thing and makes it much less readable/understandable by others).
– Szymon Maszke
Mar 23 at 11:34
You missed the actual problem with his code and created highly complex regex which does not work any better (only clutters the whole thing and makes it much less readable/understandable by others).
– Szymon Maszke
Mar 23 at 11:34
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55313044%2fsplitting-and-extracting-values-from-a-row%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown