'in CSV file. I would like to extract several values using df.loc and apply the calculation formula to each of these values using python

in CSV file. I would like to extract several values using df.loc and apply the calculation formula to each of these values.

try:
    args = sys.argv
    curdir = os.path.dirname(args[0])



    for path in glob.glob(curdir + '/output/*.csv'):
        f = open(path, 'r')
        df = pd.read_csv(f)
        # print(df)
        time1 = df.loc[:, 'TIME']

There are several values and I want to apply the formula below to each of these values. The formula I want to apply is this. = (value/86400) + 25569

ex) Sample example

        TIME       count
0    1645662056  2484200580
1    1645662057  2484218640


Solution 1:[1]

try like this:

df = pd.DataFrame([ 1645662056, 1645662057], columns = ['time'])    
df = df.assign(count = lambda x: ((x['time'] /86400) + 25569) )

Output I get:

    time    count
0   1645662056  44616.014537
1   1645662057  44616.014549

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1