I have a .df
that looks something like this(df = pandas.read_csv(main_db)
):
itemName | itemBrand | itemCode | itemStock |
---|---|---|---|
some name | some brand | a 6 digit number | some low number |
even more names | even more brands | nore 6-digit numbers | more stocks |
Looks like that but with actual names and brands.
Now if I use result = df[df['itemCode']==itemCode]
, I get:
blank | itemName | itemBrand | itemCode | itemStock |
---|---|---|---|---|
6 | itemname7 | itembrand7 | 905616 | 13 |
It’s very good. I spend too damn long looking for this. Now, I’m looking to get only the itemStock
(In this case 13) to use somewhere else. So here I use result2 = result['itemStock']
.
6 | 13 |
---|
Name: itemStock, dtype: int64
Hm. okay, not what I wanted. What can I do to get only 13
?
Advertisement
Answer
If you use:
JavaScript
x
2
1
result2 = result['itemStock']
2
it returns you a data series so you see also the index and not only the value you want. You can check it using
JavaScript
1
2
1
type(result2)
2
You can find what you want using .values attribute
JavaScript
1
2
1
result2 = result['itemStock'].values
2