pandas - Python: Performing a function on a column in a CSV and appending that CSV -


i created function parses filename constituent parts, including camera information , time stamp. want preform function (and part relevant me time stamp want return) on column of csv contains filename in first column.

    exx, mean   filename 0   1.14e-33    cam0_006806_418.852.csv 1   4.54e-05    cam0_006807_418.910.csv 2   4.48e-05    cam0_006808_418.975.csv 3   0.000138274 cam0_006809_419.037.csv 4   0.000118886 cam0_006810_419.097.csv 5   0.001155703 cam0_006811_419.157.csv 

i want add parsed time fourth column. have far

def csvdecode(f):      s = os.path.basename(f)     pattern = "".join([r'cam(?p<cam_id>[0-9]+)_',                     r'(?p<frame_id>[0-9]+)_'                     r'(?p<time>[0-9]+.[0-9]+)'])     m = re.search(pattern, s)     d = {'camera id': m.group('cam_id'),         'frame id': m.group('frame_id'),         'timestamp (s)': float(m.group('time'))}     return d['timestamp (s)']     # returns "time" portion of timestamp   df = pd.read_csv('results_avg_optical_strain.csv')  df['time (s)'] = df['filename'].apply(csvdecode) 

and runs no errors nothing added existing csv. appreciated, thanks!

to add column .csv using pandas need is

df['column name'] = 'something' 

this automatically update .csv include column. populate value length matches length of other columns in .csv


Comments

Popular posts from this blog

node.js - Node js - Trying to send POST request, but it is not loading javascript content -

javascript - Replicate keyboard event with html button -

javascript - Web audio api 5.1 surround example not working in firefox -