Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- """
- Unable to get the timestamp_shift working on the billing tool
- Taking matters into my own hands
- In this case, these is 5 hours behind the CDRs that we have
- """
- import pandas as pd
- input_file = "sample.csv"
- output_file = "time_fixed.csv"
- # set this to the amount of hours you want to roll forward or backwards
- time_shift = -5
- date_time = 2
- def print_checks(input_df, time_shift, date_time):
- print(input_df.head())
- print("__________")
- print(time_shift)
- print("__________")
- print(input_df[input_df.columns[date_time]])
- def time_shifter(input_df, time_shift, date_time):
- print_checks(input_df, time_shift, date_time)
- input_df.set_index(input_df.columns[date_time], inplace=True)
- print(input_df.head())
- #input_df[input_df.columns[date_time]] = input_df.to_datetime(input_df.columns[date_time])
- input_df.index = input_df.index.to_datetime()
- input_df.index = input_df.index + pd.DateOffset(hours=time_shift)
- print(input_df.head())
- input_df.reset_index(inplace=True)
- return input_df
- input_df = pd.read_csv(input_file)
- output_df = time_shifter(input_df, time_shift, date_time)
- output_df.to_csv(output_file, index=False)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement