我试图按日期和时间提取某一时间范围内的所有行(例如,在05/24/2021 12:50和07/24/2021 21:00之间。我所使用的数据如下所示。
我现在的代码是。
import pandas as pd
df = pd.read_csv(r"C:\Users\OneDrive\Desktop\entries-88339.csv") #to read a CSV
print(df) #print original data
df.head()
df_rename = df.rename(columns = {'DATE': 'ENTRY DATE'}) #ENTRY DATE = DATE column
print(df_rename)
df_date = df_rename[(df_rename['ENTRY DATE'] <= '05-26-21') & (df_rename['ENTRY DATE'] > '05-03-21')] #date timeframe
print(df_date)
path = '/Users/Desktop' #for exporting to new csv
new_file = 'New_file.csv'
df_date.to_csv(new_file, index = False) #index = False is no index to csv