I'm new to Lua so please bear with this simple question :)
I'm simply trying to iterate over a table, and modify it's values. however, it seems I can't modify directly the "value" part?
code:
for id,value in pairs(some_table) do
value = value * some_math_here
end
will i actually need to modify some_table[id] instead, or is there a more elegant way?
You will actually need to modify
some_table[id]
instead. value does not actually represent some_table[id]
Related
I'm planning to overwrite a Field value using pandas but that does not seem to work. Am i missing anything as part of the code below?
`for row_no in range(df.shape[0]):
rowIndex = df.index[row_no]
if re.search('Fex|Process|PIP|VIP|Generic|Mobility', df.loc[rowIndex].VPC_Sub_Cat, re.I):
print(df.loc[rowIndex].Headline)
print(df.loc[rowIndex].VPC_Sub_Cat)
print(df.loc[rowIndex].Final_Result)
df.loc[rowIndex].Final_Result = 0
print(df.loc[rowIndex].Final_Result)
break`
The output that I get after running this piece of code is:
This is the description of the issue...
VPC-Generic
1
1
Also can i achieve the same thing using a function and applying that on a data frame? kindly let me know.
df.loc[rowIndex].Final_Result is equals to (in most situation though...)
df.loc[rowIndex]['Final_Result']
This will cause a chained assignment (see here #Warning)
Whether a copy or a reference is returned for a setting operation, may depend on the context. This is sometimes called chained assignment and should be avoided. See Returning a View versus Copy.
And then from Returning a view versus a copy
But it turns out that assigning to the product of chained indexing has inherently unpredictable results.
So using df.loc[rowIndex, 'Final_Result'] to make sure that the value you assigned is view, not copy.
TLDR: I have 2 arrays indices = numpy.arange(9) and another that contains some of the numbers in indices (maybe none at all, maybe it'll contain [2,4,7]). The output I'd like for this example is [0,1,3,5,6,8]. What method can be used to achieve this?
Edit: I found a method which works somewhat: casting both arrays to a set then taking the difference of the two does give the correct result, but as a set, even if I pass this result to a numpy.array(). I'll update this if I find a solution for that.
Edit2: Casting the result of the subtraction to a list, then casting passing that to a numpy.array() resolved my issue.
I guess I posted this question a little prematurely, given that I found the solution for it myself, but maybe this'll be useful to somebody in future!
You can make use of boolean masking:-
indices[~numpy.isin(indices,[2,4,7])]
Explanation:-
we are using numpy.isin() method to find out the values exists or not in incides array and then using ~ so that this gives opposite result and finally we are passing this boolean mask to indices
I tried to append two hash tables in velocity.
#foreach($dun1 in $dotcontent.pull("+structureName:Checnas +(conhost:fe1d98e8-9699-4f3f-abf5-a6c0afc8ab47 conhost:SYSTEM_HOST)",10,"modDate desc"))
#set($foo={
$!{dun1.mname}:$!{dun1.subname}
})
#end
In the above for each loop I am pulling content from structure "Checnas".
But at the end we can get only the last value in the content.To solve that we need to append for every iteration.I need syntax for appending hash tables.
Please help me to solve this.
Your code currently is over writing $foo each time and hence you are just getting the last value. You can use lists in velocity to achieve this.
This might work:
#set($listOfMnames=[])
#set($listOfSubNames=[])
#foreach($dun1 in $dotcontent.pull("+structureName:Checnas +(conhost:fe1d98e8-9699-4f3f-abf5-a6c0afc8ab47 conhost:SYSTEM_HOST)",10,"modDate desc"))
#set($foo=$listOfMnames.add($!{dun1.mname}))
#set($foo=$listOfSubNames.add($!{dun1.subname}))
#end
This way, you will end up with two lists 'listOfMnames' and 'listOfSubNames', both fully populated. You can later iterate through them to print/utilise their values.
This link will be helpful and tell you the purpose of using $foo which is not being used and just being assigned.
Alternatively, you can also use velocity maps with proper key/val pairs but be sure to declare it before the loop begins.
Ok, I'm totally at a loss with this....
I think I have looked at every example and every code snippet around and still can't work out how to implement a custom sorter on my ObjectListView.
My primary column (column 0) contains numbers only (as a string) but is sorting all items by alphanumeric instead of numeric, meaning that it is doing something like this:
1
11
111
2
22
etc.
I am trying to find a relatively simple example of how to modify my ObjectListView to sort column 0 when it first loads, but I'm struggling.
I have converted over a custom class called ColumnSorter (from CodeProject) into VB and I'm calling the following delegate:
lvwColumnSorter = New CustomLVSorter.CustomLVSorter()
lsv_OpenTickets.CustomSorter = Sub(column As OLVColumn, order As SortOrder)
lvwColumnSorter.ColumnToSort = Ticket_Status.Index
lvwColumnSorter._SortModifier = CustomLVSorter.CustomLVSorter.SortModifiers.SortByText
lvwColumnSorter.OrderOfSort = SortOrder.Ascending
lsv_OpenTickets.ListViewItemSorter = lvwColumnSorter
End Sub
I get no errors, but I also get no change.
Any help would be greatly appreciated.
Well, are you sure you have looked at every example? I think there are a lot of resources on this one.
When you're using a list, datagridview, or any main form, you can adjust it to use a custom sorter. You create a custom IComparer, i.e. the definition of how you sort something. It can be as simple as converting the string (like yours) to an int with CInt() and returning -1 or +1 if it is greater or less than the last value. This is very common.
If you need help on the basics of how to do it, of course there are always the microsoft links that give you the basics such as Custom Sort I Comparer. But there is a stack flow that also follow your problem here: Custom sort C#
It's in C#, but there are many converters on that around here.
But the easiest way to get around it? Convert your string list into a integer list. Then it will sort perfectly.
Here is the single line from one of my functions to test if any objects in my array have a given property with a matching value
Return ((From tag In DataCache.Tags Where (tag.FldTag = strtagname) Select tag).Count = 1)
WHERE....
DataCache.Tags is an array of custom objects
strtagname = "brazil"
and brazil is definitely a tag name stored within one of the custom objects in the array.
However the function continually returns false.
Can someone confirm to me that the above should or should not work.
and if it wont work can someone tell me the best way to test if any of the objects in the array contain a property with a specific value.
I suppose in summary I am looking for the equivalent of a SQL EXISTS statement.
Many thanks in hope.
Your code is currently checking whether the count is exactly one.
The equivalent of EXISTS in LINQ is Any. You want something like:
Return DataCache.Tags.Any(Function(tag) tag.FldTag = strtagname)
(Miraculously it looks like that syntax may be about right... it looks like the docs examples...)
Many Thanks for the response.
Your code did not work. Then I realised that I was comparing to an array value so it would be case sensitive.
However glad I asked the question, as I found a better way than mine.
Many thanks again !