Question: I have a dataframe with headers 'Category', 'Factor1', 'Factor2', 'Factor3', 'Factor4', 'UseFactorA', 'UseFactorB'.

The value of 'UseFactorA' and 'UseFactorB' are one of the strings ['Factor1', 'Factor2', 'Factor3', 'Factor4'], keyed based on the value in 'Category'.

I want to generate a column, 'Result', which equals dataframe[UseFactorA]/dataframe[UseFactorB]

Take the below dataframe as an example:

```
[Category] [Factor1] [Factor2] [Factor3] [Factor4] [useFactor1] [useFactor2]
     A         1        2         5           8     'Factor1'    'Factor3'
     B         2        7         4           2     'Factor3'    'Factor1'

```

The 'Result' series should be [2, .2]

However, I cannot figure out how to feed the value of useFactor1 and useFactor2 into an index to make this happen--if the columns to use were fixed, I would just give

```
df['Result'] = df['Factor1']/df['Factor2']

```

However, when I try to give

```
df['Results'] = df[df['useFactorA']]/df[df['useFactorB']]

```

I get the error

```
ValueError: Wrong number of items passed 3842, placement implies 1

```

Is there a method for doing what I am trying here?

Answer: 
Try:

```
$ ip=10.10.10.10
$ echo "${ip%.*}.0"
10.10.10.0

```

1. `${ip%.*}` removes the last dot and the numbers after it.
2. `.0` adds `.0` to the end of the string.
3. This approach uses only shell making it faster than methods which require a pipeline.
4. It is best practice to use lower or mixed case for your variables. The system uses all upper-dase variables and you don't want to accidentally overwrite one of them.
XOR by 1 (Bash 4 for the Parameter Expansion):

```
ipv4_address="${ipv4_address%.*}.$(( ${ipv4_address##*.} ^ 1 ))"

```