data = [['tom', 10], ['nick', 15], ['juli', 14]]
df = pd.DataFrame(data, columns = ['Name', 'Age'], index = [7,3,9])
display(df)
df.iat[0,0]
I'd like to return the Age in first row (basically something like df.iat[0,'Age']. Expected result = 10
Thanks for your help!
df['Age'].iloc[0] works too, similar to what Chris had answered.
Use iloc and Index.get_loc:
df.iloc[0, df.columns.get_loc("Age")]
Output:
10
Related
Can someone please help me?
I can't get seems to work it.
What else should I do?
Here is my code
=ARRAYFORMULA(IF(AND(Y2:Y="VUL",L2:L="ANNUAL"),V2:V*0.03,IF(AND(Y2:Y="VUL",L2:L="QUARTERLY"),V2:V>0,IF(AND(Y2:Y="VUL",L2:L="SEMI ANNUAL"),V2:V*AB2:AB,"0"))))
The results must be from 2nd row to last but only works only for 2nd row.
Use ifs(), like this:
=arrayformula(
ifs(
Y2:Y <> "vul", iferror(1/0),
L2:L = "annual", V2:V * 0.03,
L2:L = "quarterly", V2:V > 0,
L2:L = "semi annual", V2:V * AB2:AB,
true, iferror(1/0)
)
)
use:
=ARRAYFORMULA(IF((Y2:Y="VUL")*(L2:L="ANNUAL"), V2:V*0.03,
IF((Y2:Y="VUL")*(L2:L="QUARTERLY"), V2:V>0,
IF((Y2:Y="VUL")*(L2:L="SEMI ANNUAL"), V2:V*AB2:AB, "0"))))
AND is *
OR is +
Got the rights answer
thank you so much guys
=ARRAYFORMULA(IF((Y2:Y="VUL")*(L2:L="ANNUAL"),V2:V*0.03,
IF((Y2:Y="VUL")*(L2:L="QUARTERLY")*(V2:V>0), V2:V*AB2:AB,
IF((Y2:Y="VUL")*(L2:L="SEMI ANNUAL")*(V2:V>0), V2:V*AB2:AB, "0"))))
How do I get multiple answers from the text using BertForQuestionAnswering, just like for the below question there are two possible answers
a nice puppet
a software engineer
Below is the code snippet for the same:
from transformers import BertTokenizer, BertForQuestionAnswering
import torch
tokenizer = BertTokenizer.from_pretrained('bert-base-uncased')
model = BertForQuestionAnswering.from_pretrained('bert-large-uncased-whole-word-masking-finetuned-squad')
question, text = "Who was Jim Henson?", "Jim Henson was a nice puppet.Jim Henson was a software engineer."
input_ids = tokenizer.encode(question, text)
token_type_ids = [0 if i <= input_ids.index(102) else 1 for i in range(len(input_ids))]
start_scores, end_scores = model(torch.tensor([input_ids]), token_type_ids=torch.tensor([token_type_ids]))
all_tokens = tokenizer.convert_ids_to_tokens(input_ids)
answer = ' '.join(all_tokens[torch.argmax(start_scores) : torch.argmax(end_scores)+1])
print(answer)
'a software engineer' ```
Thanks in advance!!
You are simply outputting the most likely answer according to BERT. If you want multiple answers, you will need to actually select multiple answers. In this case that would be the first and second most likely answer. To do this, create a new answer variable and select the second most likely start and answer word from the start_scores and end_scores variable. I recommend you use at torch.topk()
answer1_start, answer2_start = torch.topk(start_scores)
answer2_end, answer2_end = torch.topk(end_scores)
answer1 = ' '.join(all_tokens[answer1_start : answer1_end + 1])
answer2 = ' '.join(all_tokens[answer2_start : answer2_end + 1])
print(answer1, answer2)
Let me know how this works.
myMesh = {}
myMesh[0].x = 30
Nope... doesn't work.
myMesh = Mesh.new{}
myMesh[0].x = 30
Nope... no go.
An array of meshes should be possible, but I don't know how. Can someone help? Thanks
Edit:
Thanks for your responses. Pardon me for this stupid mistake. I just realized, "What nonsense are you doing J?" I really wanted an array of vertices of the mesh, so that I can use loops to manipulate them. Sorry about that... although it didn't hurt to learn how to get an array of meshes.
So I figured it out, because I was sure I did this before, when I used gml.
ptx = {}; pty = {}; ptz = {}
ptx[1] = myMesh.x; pty[1] = myMesh.y; ptz[1] = myMesh.z;
Thanks for the help though. I also learned that lua doesn't use index 0
Edit: Wait. That doesn't work either does it?
Well for now this gives no error, so I'll see if it does what I want.
pMesh = {}
for m=1, 6 do
pMesh[m] = Mesh.new()
end
pMesh[1].x = 0; pMesh[1].y = 0; pMesh[1].z = 0
Thanks guys. If you have any other suggestions, I'm all ears.
myMesh = {}
myMesh[0].x = 30
Will cause an error for indexing a nil value.
myMesh = {} creates an empty Lua table.
doing myMesh[0].x is not allowed because there is no myMesh[0].
First you have to insert a table element at index 0.
myMesh = {}
myMesh[0] = Mesh.new(true)
myMesh[0].x = 30
myMesh is a stupid name for an array of meshes as it suggests it's just a single mesh.
Also in Lua we usually start with index 1 which will makes things a bit easier using Lua's standard table tools.
I'm not sure if
mesh = Mesh.new()
mesh.x = 30
is actually ok. Why would a mesh have an x coordinate? This is not listed in Mesh's properties in the manual.
Usually you would create a Mesh with multiple points And if you want an array of multiple meshes you would simply put those meshes into a table unless there is a particular user data type for this.
Try this:
myMesh = {}
myMesh[0]= Mesh.new{}
myMesh[0].x = 30
you need to initialize as a table and columns and rows:
myMesh = {}
myMesh[0] = {}
myMesh[0].x=30
or
myMesh = { [0]={} }
myMesh[0].x=30
This question already has answers here:
Why does Lua's length (#) operator return unexpected values?
(2 answers)
Closed 6 years ago.
I am new to lua and my lua version is 5.1.
I've got this problem. Can anybody help me to explain '#'?
local tblTest =
{
[1] = 2,
[2] = 5,
[5] = 10,
}
print(#tblTest)
this output 2 and ..
local tblTest =
{
[1] = 2,
[2] = 5,
[4] = 10,
}
print(#tblTest)
output is 4. Why?
thanks all of u.
The output is 4 because the last key with a value is 4 but that doesn't mean that 3 isn't also defined. In lua 3 would be defined as nil. So when you use the # operator it counts every key in a sequence with a value until the last non-nil value. Except,(and I could be wrong about this) the last key in the table is a power of 2, which do to language optimization, it counts up to the value that is a power of 2. In general you should stay away from tables with nil values as there are some other weird behaviors that happen because of this.
This chunk with do what you want though:
local T = {
[1] = 2,
[2] = 5,
[10] = 10
}
local lengthNum = 0
For k, v in pairs(T) do -- for every key in the table with a corresponding non-nil value
lengthNum = lengthNum + 1
end
print(lengthNum)
}
What this does is it checks the entire table for keys (such as [1] or [2]) and checks if they have value. Every key with a non-nil value runs the for loop one more time. There might be a shorter way to this, but this is how I would do it.
This is my first attempt to use Lua tables and I'm getting on with it quite well. I'm struggling with one thing though, heres (a small sample of) my table as it currently stands:
objects = {
["1/1/1"] = { tl = 1, startVal = 1, stopVal = 0 },
["1/1/2"] = { tl = 11, startVal = 1, stopVal = 0 },
["1/1/3"] = { tl = 22, startVal = 1, stopVal = 0 },
["1/1/4"] = { tl = 33, startVal = 1, stopVal = 0 },
}
The typical operation of this is that I use the "1/1/1" values as a lookup to the inner tables and then use those values in various functions. This all works well. Now, I need to go the other way, say I have tl = 22 coming in, I want to return the top value ("1/1/3" in this case).
I think I need to do something with the inpairs I keep seeing on the web but I'm struggling to implement. Any help would be massively appreciated.
You can't use ipairs because your table is an associated array not a sequence, so you have to use pairs. Also, there is no search function builtin to Lua, so you have to loop over all items yourself, looking for the right field value:
function findTL(tbl)
for key, data in pairs(tbl) do
if data.tl == tlSearch then
return key
end
end
end
local key = findTL(objects, 22)
If you want something a tad more object-oriented you could do this:
objects.findTL = findTL -- ok because first arg is the table to search
local key = objects:findTL(22)
isn't it better to take the value directly?
objects.1/1/1.tl
I don't know if it will work also with slashes, but if not, you may replace it by 'x' for example. Then it will be:
objects.1x1x1.tl