Created
March 28, 2022 16:53
-
-
Save vipassanaecon/f8ea08077af0ccc919916e9aa78a15ea to your computer and use it in GitHub Desktop.
This file contains 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
#import needed package | |
import pandas as pd | |
#read file and create dataframe | |
df = pd.read_csv(r"file_path.csv", encoding= 'unicode_escape') | |
df.head() #view head of dataframe | |
#convert timestamp/datetime/etc column... from object (or other) datatype to datetime datatype if needed. | |
#longest process in this script if needed, otherwise ignore. | |
df['timestamp'] = df['timestamp'].apply(pd.Timestamp) | |
#view datatypes of your columns if needed or if you want to validate the conversion worked as needed. | |
print(df.dtypes) | |
#sort timestamp/datetime column | |
df.sort_values(by=['timestamp'], ascending=True) | |
#create new sorted csv file | |
df.to_csv(r"file_path_sorted.csv") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment