Section XV pandas setup time index

Import PANDAS AS PD 
pd.options.display.max_rows = 10   # The number of lines displayed 

DF1 = pd.read_csv (R & lt ' E: \ anacondatest \ PythonData \ of PM25 \ Beijing_2009_HourlyPM25_created20140709.csv ' , encoding = ' GBK ' ) 

# converts the data into a timestamp type 
pd.Timestamp (DF1 [ " a Date (the LST) " ] [0]) 

# establish datetimeindex objects 
df1idx = df1.set_index (pd.to_datetime (DF1 [ " a Date (the LST) " ])) 

# -based index Quick slicing 
Print (df1idx [ " 2018-11-1 " : "2018-11-5 " ]) 

# make the time series basic process 
Print (df1idx.index.hour)   # directly fetches the corresponding level index 
df1idx.groupby (df1idx.index.month) .max ()   # directly groupby Summary 

# value processing sequence deletions using REINDEX 
df2idx = df1.set_index (pd.to_datetime (DF1 [ " a Date (the LST) " ]))   # set the index 
IDX = pd.date_range (Start = ' 2009-2-1 00:00:00 ' , End = ' 2009-12-31 00:00:00 ' )   # custom a sequence index 
df2idx.reindex (IDX)   # reset index custom index 
df2idx [df2idx.index.duplicated ()]   #Re-check the data 
df2idx [~ df2idx.index.duplicated ()]. REINDEX (IDX, Method = ' bfill ' )   # the data as an index to re-re

 

Guess you like

Origin www.cnblogs.com/kogmaw/p/12563486.html