Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 2 years ago.
Improve this question
I want to migrate the data to a target table.
However, I want to make a reject file for null values and values whose size exceeds 20 characters. As I do with Conditional Splitting?
I did that but it doesn't work:
"if len(mail)>10 caractère"
i will export this values to reject file
How can i do this Please ?
Design
You can do this directly in a conditional split but I advise against doing so. Instead, compute the boolean (true/false) condition in a Derived Column and add that to your data flow. Then, if you get unexpected results, you can add a data viewer between the Derived Column step and the Conditional Split
Implementation
Add a Derived Column to the data flow. Add a new column called BadMail. If it's true, then we'll route to the bad file. If it's true, it will proceed to the destination.
The Expression language for SSIS will use the ternary operator (test) ? true_condition : false_condition
I am going to test for null ISNULL(mail), longer than 20 len(mail) > 20 and zero length len(mail) == 0.
The || is a logical or so if any of those three conditions are true, then we need to set the BadMail to true
(ISNULL(mail) || len(mail) > 20 || len(mail) == 0) ? true : false
You could simplify that to eliminate the ternary operator but I find being explicit in my intentions helpful in these situations. As a side note, if you are still having issues with unexpected results, add a preceding Derived Column transformation and add a column in for each criteria (null, 0 or greater than 20 character) and then you can inspect them individually.
Now, we add the Conditional Split
The expression here is just our new column BadMail and that will route to Output Path 1 or whatever you name it. The good mail will pass through to the default output path.
Related
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 5 months ago.
Improve this question
Page 109 of The AWK Programming Language book has a statement to create a 2-D array named attr:
attr[nrel, $1] = ++nattr[nrel]
nrel = an integer representing the number of relations (tables)
nattr = an integer representing the number of attributes (table columns)
Substituting country for $1, 1 for nrel, and 1 for nattr we have:
attr[1, country] = 1[1]
What does the right-hand side of that statement mean? It appears to be referencing subscript 1 of array 1. Can an array be named 1? Would you explain what that expression means, please?
Page 109(...)
I have look into archive.org's version and line
attr[nrel, $1] = ++nattr[nrel]
is sole line referencing nattr and therefore this is where nattr is created, as you are asking about value under key it will be array. You might check that by substituting all but nattr as proposed and using typeof function
awk 'BEGIN{attr[1, "France"] = ++nattr[1];print typeof(nattr)}' emptyfile
gives output
array
therefore shown line does firstly increase value in array nattr under key nrel and then assign such changed value to array attr under key nrel, $1.
(tested in gawk 4.2.1)
Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 1 year ago.
Improve this question
I have a dataframe which looks as following:
df['col1'].values
array(['cat 113kd29', 'do56goat24kdasd', 'pig145kd'])
I need to create a new column df['vals'] with following values:
cat 29
do56goatasd
pig
i.e. first I need to look for substring kd and then find the numeric value preceding it. I am not sure how to go about this.
There can be multiple numeric values in each string so I need to find only ones before kd. Please note the string 'cat 113kd29'. Also look at 'do56goat24kdasd'
I tried the following but it didn't work:
df['col1'].str.replace(r'(\d+)kd', '')
Your call to str.replace is correct, but you need to assign it to the original Pandas column on the left hand side of an assignment:
df["col1"] = df["col1"].str.replace(r'\d+kd', '')
Note that str.replace does a global replacement by default, so there is no need to use any sort of flag.
Another way is to match digits precedingkd and kd and replace it with nothing
df["col1"]=df.col1.str.replace('\d+kd\Z','', regex=True)
Closed. This question is opinion-based. It is not currently accepting answers.
Want to improve this question? Update the question so it can be answered with facts and citations by editing this post.
Closed 2 years ago.
Improve this question
As far I as my experience tells me, boolean variables usually named in format - is/has+noun/adj/verb, e.g isValid, isButton, hasClickedLink
But say there is the case where we have some flag which straightly tells whether to do something, like for example, clean to indicate that cleanup function should be automatically called in the end.
How to name such a booleans? Same clean - is ambiguous, looks like a method name more, but naming it toClean is, I don't know, too weird. Or should I name it like callCleanup?
Thanks in advance!
In this case i usually append the word wanted, which makes cleanWanted. In general, for boolean variables I also prefer to always let the last word be an adjective. This makes it very clear that it represents a truth value. The is/has prefix is often superfluous, as in hasClickedLink which is more concisely communicated with linkClicked.
methods are usually one word adjectives with a capitol at the start
maybe create a method that sets the flag
for example
void Clean(){
clean = True;
}
I would like to ask you if you could please explain the anatomy of the Openerp domain filters. I have to use it my project.
Please explain the description of the following domain filter.
['|',('order_id.user_id','=',user.id),('order_id.user_id','=',False)]
I want to know the exact meaning of (order_id.user_id','=',user.id), what is order_id, user_id, and user.id. Are they referencing any table. If yes then how am I supposed to know which one...
Basically I want to know decipher the notation from bottom up so that can use it as per my requirement.
This one is pretty simple.
Consider the following fields (only XML i've given here, python you got to manage)
<field name="a"/>
<field name="b"/>
<field name="c"/>
Single Condition
Consider some simple conditions in programming
if a = 5 # where a is the variable and 5 is the value
In Open ERP domain filter it would be written this way
[('a','=',5)] # where a should be a field in the model and 5 will be the value
So the syntax we derive is
('field_name', 'operator', value)
Now let's try to apply another field in place of static value 5
[('a','=',b)] # where a and b should be the fields in the model
In the above you've to note that first variable a is enclosed with single quotes whereas the value b is not. The variable to be compared will be always first and will be enclosed with single quotes and the value will be just the field name. But if you want to compare variable a with the value 'b' you've to do the below
[('a','=','b')] # where only a is the field name and b is the value (field b's value will not be taken for comparison in this case)
Condition AND
In Programming
if a = 5 and b = 10
In Open ERP domain filter
[('a','=',5),('b','=',10)]
Note that if you don't specify any condition at the beginning and condition will be applied. If you want to replace static values you can simply remove the 5 and give the field name (strictly without quotes)
[('a','=',c),('b','=',c)]
Condition OR
In Programming
if a = 5 or b = 10
In Open ERP domain filter
['|',('a','=',5),('b','=',10)]
Note that the , indicates that it's and condition. If you want to replace fields you can simply remove the 5 and give the field name (strictly without quotes)
Multiple Conditions
In Programming
if a = 5 or (b != 10 and c = 12)
In Open ERP domain filter
['|',('a','=',5),('&',('b','!=',10),('c','=',12))]
Also this post from Arya will be greatly helpful to you. Cheers!!
The '|' is an OR that gets applied to the next comparison. The (..., '=', False) gets converted into an IS NULL so the SQL for this would be
WHERE order_id.user_id = x OR order_id.user_id is NULL
The default is AND which is why you don't see ('&', ('field1', '=' ,1), ('field2' ,'=', 2) everywhere.
Note that another useful one is ('field1', '!=', False) which gets converted to WHERE field1 IS NOT NULL
There isn't a lot of great documentation for this and they get quite tricky with multiple operators as you have to work through the tuples in reverse consuming the operators. I find I use complex ones infrequently enough that I just turn on query logging in Postgres and use trial and error observing the generated queries until I get it right.
Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions asking for code must demonstrate a minimal understanding of the problem being solved. Include attempted solutions, why they didn't work, and the expected results. See also: Stack Overflow question checklist
Closed 9 years ago.
Improve this question
I have my excel sheet data(i converted into array format) which looks like following
1st row......['one', , , , 'Folder', 'Folder', 'Extended Data', 'Extended Data', 'Extended Data','Extended Data' ],
2nd row.....['ID', 'Label', 'Longitude', 'Latitude', 'Country', 'City', 'Inventory', 'Safety stock', 'weight', 'hdsjka'],
3rd row......['AFKBL', 'Kabul, Afghanistan', 69.136749, 34.53091, 'Afghanistan', 'Kabul', 12, 1845, 12, 1845],
4th row......['AFKDH', 'Kandahar, Afghanistan', 65.700279, 31.61087, 'Afghanistan', 'Kandahar', 18, 1193, 18, 1193], ....etc etc
I want to pull all the values in the 2nd row that comes under 'Extended Data' ( which is in 1st row)
and write it into a single column array in a different file..
I want to use this column array for creating a control wrapper in google charts.
I would really appreciate if anybody could write a macro and help me on this..
I can't quite make out how what your array looks like, but it seems to me that the data you want should be simple to obtain by looping across the array cells.
Say the data you want is in row 2 and columns 4 to 7 of the array you already have ("oldarr"), then you just create a new array of newarr(4,1).
dim newarr(4,1)
for j = 1 to 4
newarr(j,1) = arr(2, (j+3)) ''cycles across the needed columns on the second row
next j
You can then paste the contents of newarr wherever you like.
Now, this seems much too simple to require a macro to do, which is why I think I have to be missing something. However, the general approach holds as long as you know which array columns will contain the information you want. The only subtleties I could think of would be if you don't know how many rows or columns you need to copy in each iteration (in which case you could use a dynamic array), or if the columns containing "Extended Data" can change.
Hope this can at least help you get started.