1234567891011121314151617181920 |
- import pandas as pd
- def csv_interpolate_by_frame(input, output):
- df = pd.read_csv(input)
- df['simFrame'] = pd.to_numeric(df['simFrame'], errors='coerce')
- df = df.sort_values(by='simFrame')
- full_simFrame_series = pd.Series(range(df['simFrame'].min(), df['simFrame'].max() + 1))
- df = df.merge(full_simFrame_series.rename('simFrame'), how='right')
- df = df.interpolate(method='linear')
- df['simFrame'] = df['simFrame'].astype(int)
- df.to_csv(output, index=False)
- if __name__ == '__main__':
- input_file = 'input.csv'
- output_file = 'output.csv'
- csv_interpolate_by_frame(input_file, output_file)
|