Unable to overwrite a Column Value using Pandas - pandas

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.

Related

LabVIEW - How to clear an array after each iteration in a for loop

I'm trying to clear an array after each iteration of a for loop in LabVIEW, but the way I've implemented it has the values not going directly to what I want, but it changes with previous values in other parts of the array.
It isn't shown, but this code is inside of a for-loop that iterates through another numeric array.
I know that if I get the array to clear properly after each loop iteration, this should work. How do I do that? I'm a beginner at Labview but have been coding for awhile - help is appreciated!!!
[![labview add to array][2]][2]
It looks as if you're not quite used to how LabVIEW passes data around yet. There's no need to use lots of value property nodes for the same control or indicator within one structure; if you want to use the same data in more than one place, just branch the wire. Perhaps you're thinking that a LabVIEW control or indicator is equivalent to a variable in text languages, and you need to use a property node to get or set it. Instead, think of the wire as the variable. If you want to pass the output of one operation to the input of another, just wire the output to the input.
The indicators with terminals inside your loop will be updated with new values every loop iteration, and the code inside the loop should execute faster than a human can read those values, so once the loop has finished all the outputs except the final values will be lost. Is that what you intended, or do you want to accumulate or store them in some way?
I can see that in each loop iteration you're reading two values from a config file, and the section is specified by the string value of one element of the numeric array Array. You're displaying the two values in the indicators PICKERING and SUBUNIT. If you can describe in words (or pseudocode, or a text language you're used to) what manipulation of data you're actually trying to do in the rest of this code, we may be able to make more specific suggestions.
First of all, I'm assuming that the desired order of operations is the following:
Putting the value of Pickering into Array 2
Extracting from Array 2 the values to put in Pickering 1 and Pickering 2
Putting Array 2 back to its original value
If this is the case, with your current code you can't be sure that operation 1 will be executed be fore operation 2. In fact, the order of these operations can't be pre-determined. You must force the dataflow, for example by creating a sequence structure. You will put the code related to 1 in the first frame, then code related to operation 2 in the second.
Then, to put Array 2 back to it's original value I would add a third frame, where you force an empty array into the Value property node of Array 2 (the tool you use for pickering, but as input and not as output).
The sequence structure has to be inside the for loop.
I have never used the property node Reinit to default, so I can't help you with that.
Unfortunately I can't run Labview on this PC but I hope my explanation was clear enough, if not tell me and I will try to be more specific.

SHOW KEYS in Aerospike?

I'm new to Aerospike and am probably missing something fundamental, but I'm trying to see an enumeration of the Keys in a Set (I'm purposefully avoiding the word "list" because it's a datatype).
For example,
To see all the Namespaces, the docs say to use SHOW NAMESPACES
To see all the Sets, we can use SHOW SETS
If I want to see all the unique Keys in a Set ... what command can I use?
It seems like one can use client.scan() ... but that seems like a super heavy way to get just the key (since it fetches all the bin data as well).
Any recommendations are appreciated! As of right now, I'm thinking of inserting (deleting) into (from) a meta-record.
Thank you #pgupta for pointing me in the right direction.
This actually has two parts:
In order to retrieve original keys from the server, one must -- during put() calls -- set policy to save the key value server-side (otherwise, it seems only a digest/hash is stored?).
Here's an example in Python:
aerospike_client.put(key, {'bin': 'value'}, policy={'key': aerospike.POLICY_KEY_SEND})
Then (modified Aerospike's own documentation), you perform a scan and set the policy to not return the bin data. From this, you can extract the keys:
Example:
keys = []
scan = client.scan('namespace', 'set')
scan_opts = { 'concurrent': True, 'nobins': True, 'priority': aerospike.SCAN_PRIORITY_MEDIUM }
for x in (scan.results(policy=scan_opts)): keys.append(x[0][2])
The need to iterate over the result still seems a little clunky to me; I still think that using a 'master-key' Record to store a list of all the other keys will be more performant, in my case -- in this way, I can simply make one get() call to the Aerospike server to retrieve the list.
You can choose not bring the data back by setting includeBinData in ScanPolicy to false.

How to append hash tables in velocity template?

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.

Sibling model function in Qt5

We had the following code to retrieve data of type TYPE through a model, which is a custom proxy model. This is required by the next QSortFilterProxyModel to make the decision about filtering of elements. The code is actually combined from 2 functions: in the project we usually have some arbitrary index related to some ROW and use it to retrive the data from another predefined column which contains TYPE data.
QModelIndex index = sourceModel()->index(row, COLUMN1, sourceParent); /* sourceParent is always'invalid' - retrieving data from top-level items*/
ModelIndex sibling = index.sibling(row, COLUMN2);
return sibling.data(Qt::EditRole).value<TYPE>();
This worked fine with Qt4 but when moved to Qt5 sibling became 'invalid'. I wonder what has happened, taking into account that the data is actually there, which I see, by changing the code to the following
return sourceModel()->index(sourceRow, COLUMN2, sourceParent).data(Qt::EditRole).value<TYPE>();
-works fine
Looking at the implementation of sibling(), I cannot tell what makes it return an invalid index in your case. Comparing with the Qt4 implementation, maybe it's around the IndexMap use.
But why don't you simply use your solution with sourceModel()->index(sourceRow, COLUMN2, sourceParent), since it already seems to be what you actually want to do?

Need Help Creating Custom Sorter On ObjectListView

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.