Substituting with regex in python does not work - regex

I have a long string containing different dummy dates and want to replace a part of a mail multiple times with different date values in my dummy_date string. The below code return 1 result substituted with the last date of dummy_date. How can I do that for all date values in the dummy_date? I cannot iterate over string. Also, when I write my string to .txt file, just last item is written.
dummy_dates= "14 B-Laycan Dec I-Laycan 2012 I-Laycan
15 B-Laycan Jan I-Laycan 2013 I-Laycan
16 B-Laycan Feb I-Laycan 2014 I-Laycan
17 B-Laycan Mar I-Laycan 2014 I-Laycan"
dummy1= re.sub(r"((\d{1,2})([\w\W]{1,10})( B-Laycan)+(([\w\W]{1,10}( I-Laycan)+){0,6}))", dummy_dates ,mail)

Related

Filter only MAX month figures Power BI Desktop

I have a table of values for orders per month by region that looks like this:
Orders Table
Orders (YTD)
Month
Year
1
Jan
2021
4
Feb
2021
4
Mar
2021
5
Apr
2021
14
May
2021
16
Jun
2021
17
Jul
2021
19
Aug
2021
22
Sep
2021
24
Oct
2021
34
Nov
2021
35
Dec
2021
1
Jan
2022
3
Feb
2022
4
Mar
2022
Along with a table that orders the months in sequence as below, that will be modelled to order the months in the first table so that they appear in sequence in graphs.
Monthly Sequence Table
Month Sequence
Month
1
Jan
2
Feb
3
Mar
4
Apr
5
May
6
Jun
7
Jul
8
Aug
9
Sep
10
Oct
11
Nov
12
Dec
Upon closer inspection of my data, I have realised that the number of orders per month are not the raw figure per month, but a cumulative total for every order in the calendar year so far (new orders for month + orders for preceding month). Firstly, I want to calculate the correct sum of orders per year, which should actually just be the MAX month from the orders table. Of course in most years this will be December, but for the current year it needs to be the latest month. I wanted to use a measure to calculate the MAX 'Monthly Sequence Table'[Month Sequence] number from each table, by year. I thought maybe a filter function would be used but could not work out exactly how to do this in DAX.
Secondly, and similarly, I want to calculate the actual number of orders per each individual month using DAX. In this case, I want to take the Orders (YTD) total for that month/year combination and subtract it from its immediately preceding month. What would the formula look like for this?
Thanks in advance.

All CSV values in column 0 are strings

For some reason a csv file I wrote (win7) with Python has all the values as a string in column 0 and cannot perform any operation.
It has no labels.
The format is (I would like to keep the last value - date - as a date format):
"Rob,Avanti,Ave,12.83,Max,4.0,Min,-21.9,analist disp:,-1.0,"" date: Feb 04, 2016 """
EDIT - When I read it with the csv module it prints it out like:
['Rob,Avanti,Ave,12.83,Max,4.0,Min,-21.9,analist disp:,-1.0," date: Feb 04, 2016\t\t\t"']
What is the best way to convert the strings into comma separated values like this?
Rob,Avanti,Ave,12.83,Max,4.0,Min,-21.9,analist disp:,-1.0, date:, Feb 04, 2016
Thanks a lot.
s="Rob,Avanti,Ave,12.83,Max,4.0,Min,-21.9,analist disp:,-1.0,"" date: Feb 04, 2016 """
print(s)
Rob,Avanti,Ave,12.83,Max,4.0,Min,-21.9,analist disp:,-1.0, date: Feb 04, 2016
to add a comma after "date:" you need to add some logic (like replace ":" with ":,"; or after first word etc.
First, your date field is quoted, which is ok (and needed) because there is a comma inside:
" date: Feb 04, 2016 "
But then the whole line also gets quoted (and thus seen as a single field). And because there are already quotes around the date field, those get escaped with another quote:
"Rob,Avanti,Ave,12.83,Max,4.0,Min,-21.9,analist disp:,-1.0,"" date: Feb 04, 2016 """
So, if you remove that last quoting, everything should be fine (but you might want to trim the date field):
Rob,Avanti,Ave,12.83,Max,4.0,Min,-21.9,analist disp:,-1.0," date: Feb 04, 2016 "
If you want it exactly like this, you need another comma after date: :
Rob,Avanti,Ave,12.83,Max,4.0,Min,-21.9,analist disp:,-1.0, date:,"Feb 04, 2016"
On the other hand, it would be better to use a header instead:
Name,Name2,Ave,Max,Min,analist disp,date
Rob,Avanti,12.83,4.0,-21.9,-1.0,"Feb 04, 2016"

How to delete the row with missing character values using SAS

I have a data set like this:
id type time
70657 23E Nov 4 2002 12:00AM
61651 12R
11603 DQ2
45819 Jul 23 2013 12:00AM
732 Mar 4 2011 12:00AM
22810 231
I want to do two things with missing values.
The first thing is how to remove the rows if the values of the variable time is " ".
desired output1
id type time
70657 23E Nov 4 2002 12:00AM
45819 Jul 23 2013 12:00AM
732 Mar 4 2011 12:00AM
The second thing is to remove the rows if there is any missing values.
desired output2
id type time
70657 23E Nov 4 2002 12:00AM
SAS code:
data character;
length id type time $ 24;
input id $ 1-5 type $ 8-10 time $ 13-31;
cards;
70657 23E Nov 4 2002 12:00AM
61651 12R
11603 DQ2
45819 Jul 23 2013 12:00AM
732 Mar 4 2011 12:00AM
22810 231
;
run;
I would be inclined to use proc sql. Something like:
proc sql;
create table newchar as
select *
from character
where id is not null and type is not null and time is not null;
quit;
The SAS alternative.
DATA WANT;
SET CHARACTER (WHERE = (TIME ~= "" AND TYPE ~= "" AND ID ~= ""));
RUN;

How can I set x-axis values in the Area Chart google visualisation

I am using Area chart by google visualisation. I need to customise the x-axis values.for example the date starts from 1 oct to 2 dec. In this I need to display only 10 values which includes the start date and the end date.
By default it displays like this.
oct 1 oct 2 oct 3 oct 4 oct 5 oct 6 oct 7 oct 8 oct 9 oct 10
But I need in this format.
oct 1 oct 7 oct 14 oct 21 oct 28 nov 4 nov 11 nov 18 nov 25 dec 2
and the values in between i.e., from start date to end date can be anything.
Any suggestions?
Thank you in advance
You can do one thing. Get input the start date and end date well then calculate its difference. After getting the difference divide it in 10 intervals. Then assign these 10 intervals to the x-axis value.

javascript regular expression: how do I find date without year or date with year<2010

I need to find date without year, or date with year<2010.
basically,
Feb 15
Feb 20
Feb 20, 2009
Feb 20, 1995
should be accepted
Feb 20, 2010
Feb 20, 2011
should be rejected
How do I do it?
Thanks,
Cheng
Try this:
(Jan|Feb|Mar...Dec)\s\d{1,2},\s([1][0-9][0-9][0-9]|200[0-9])
Note: Expand the month list with proepr names. I was too lazy to spell it all out.