Select DataFrame rows between two dates

前端 未结 10 874
挽巷
挽巷 2020-11-22 03:14

I am creating a DataFrame from a csv as follows:

stock = pd.read_csv(\'data_in/\' + filename + \'.csv\', skipinitialspace=True)

The DataFra

10条回答
  •  野性不改
    2020-11-22 04:08

    Inspired by unutbu

    print(df.dtypes)                                 #Make sure the format is 'object'. Rerunning this after index will not show values.
    columnName = 'YourColumnName'
    df[columnName+'index'] = df[columnName]          #Create a new column for index
    df.set_index(columnName+'index', inplace=True)   #To build index on the timestamp/dates
    df.loc['2020-09-03 01:00':'2020-09-06']          #Select range from the index. This is your new Dataframe.
    

提交回复
热议问题