Created
January 17, 2025 15:31
-
-
Save rsalaza4/b48c81b29f690e48fa68b9cc9780fc79 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # Calculate timeframe from input file on a minute basis | |
| # If the timespan from the source file is less than a day | |
| if (pd.to_datetime(df.iloc[-1,0]) - pd.to_datetime(df.iloc[0,0])).days == 0: | |
| timeframe = pd.date_range( | |
| df.iloc[0,0], | |
| periods=60*24, | |
| freq='1min' | |
| ) | |
| # If the timespan from the source file is more than a day | |
| else: | |
| timeframe = pd.date_range( | |
| df.iloc[0,0], | |
| periods=(pd.to_datetime(df.iloc[-1,0]) - pd.to_datetime(df.iloc[0,0])).days*60*24, | |
| freq='1min' | |
| ) | |
| # Create 'minutes' pandas data frame | |
| minutes_df = pd.DataFrame({'Business Date':timeframe}) | |
| # Add Date column | |
| minutes_df['Date'] = minutes_df['Business Date'].dt.date | |
| # Add Time column | |
| minutes_df['Time'] = minutes_df['Business Date'].dt.time | |
| # Visualize top rows | |
| minutes_df.head() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment