0

Here's an example:

Given that the dataset is a CSV file:

Column 1  Column 2  Column 3
Site #    Type      Value
0         A         0.358 
0         B         12
1         B         84
1         A         3.879
1         B         4.823
0         A         9.7892
0         B         76.54
0         A         82
2         B         13.986
2         A         15.96
2         B         14.831
0         A         14

So what I would like to do is apply a function for all Site# = '0' to multiply the Value column by 13 or something and save that new table. Something like:

Column 1  Column 2  Column 3
Site #    Type      Value
0         A         4.654 
0         B         156
1         B         84
1         A         3.879
1         B         4.823
0         A         127.2596
0         B         995.02
0         A         1066
2         B         13.986
2         A         15.96
2         B         14.831
0         A         182

Any and all help is greatly appreciated.

konsama
  • 327
  • 2
  • 12

1 Answers1

0

Use pandas library.

>>> import pandas as pd
>>> import numpy as np
>>> df = pd.read_csv('csv_file')
>>> df.columns = ["Site", "Type", "Value"]
>>> df
   Site Type    Value
0     0    B  12.0000
1     1    B  84.0000
2     1    A   3.8790
3     1    B   4.8230
4     0    A   9.7892
5     0    B  76.5400
>>> df.Value = np.where(df.Site == 0, df.Value * 13, df.Value)
>>> df
   Site Type     Value
0     0    B  156.0000
1     1    B   84.0000
2     1    A    3.8790
3     1    B    4.8230
4     0    A  127.2596
5     0    B  995.0200
abhilb
  • 5,639
  • 2
  • 20
  • 26