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)
Related
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 problem with Substring function. As you can see on Watch window shcreenshot I have the variable called val equal to 03.09.2015 17:30
I do not understand why but
val.Substring(0,2) returns 0 instead of 03
val.Substring(0,3) returns 03 (string of two symbols)
What am I doing wrong?
Your string contains non-printable characters. Note the following from your screenshot:
val = "03.09.2015 17:30"
val.Length = 21
However, 03.09.2015 17:30 only has 16 characters. Thus, the string contains other, zero-width characters.
To find the culprit, output a hex dump of your problematic string and compare it with the hex dump of the literal string 03.09.2015 17:30.
From OP comment:
The original problem was with Parse (and Parse-like) functions. It can not parse this string as Date or DateTime
Once the invisible characters are removed from the string, it certainly can be parsed:
Dim d As Date = DateTime.Parse("03.09.2015 17:30", Globalization.CultureInfo.InvariantCulture)
Dim m As Integer = d.Month ' m = 3
Of course, choose the particular Parse method that best fits your needs.
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.
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 3 years ago.
Improve this question
Trying to convert a number string into an INT64 in VB.NET. The number I am testing with is 12804494279291877304.
The error I am getting is "Value was either too large or too small for an Int64."
Code sample below.
BigInt = CLng(EncodeNumber)
It's too big, doesn't fix in a INT64. It would fit in a UINT64.
Dim v As UInt64
v = UInt64.Parse("12804494279291877304")
Like #Çöđěxěŕ said, using TryParse allow the use of proper error handling.
If Not UInt64.TryParse("12804494279291877304", v) Then
' Handle wrong input
End If
Your number is too big for Int64, so you could use BigInteger, please see https://learn.microsoft.com/en-us/dotnet/api/system.numerics.biginteger?view=netframework-4.8
You can use unsigned Int64 as others suggest but beware that it won't hold negative numbers and also has a limit of 18446744073709551615
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.
This question already has answers here:
Closed 10 years ago.
Possible Duplicate:
Remove a random expression from string
I have a column which contains values like this
"000003023_AggregateStopLossLimit_W x3A 973911_2012-12-22.PDF";
I want to create a substring which doesn't have the part x3A 973911 in it.
Whic means I want something like this,
000003023_AggregateStopLossLimit_W_2012-12-22.PDF
The value x3A 973911 is not constant, so basically, in words, I want the part of string to be removed which comes after the first space and ends at the next '_'.
Any ideas ?
String phrase="000003023_AggregateStopLossLimit_W x3A 973911_2012-12-22.PDF";
phrase.replace("x3A 973911","");
//am not sure if you have to trim() but i guess this will answer your question.