It is easy to change the layout, sort, reindex, rename, and subset table data using pandas commands. The simple code below shows you how to do this easily. The functions include melt(),pivot,sort_values,rename,sort_index,drop,filter,query,iloc,loc,iat,at and drop_duplicates.
Table of Contents
Prepare data
#dowonload https://github.com/ziwangdeng/Data/blob/main/Vancouver_weather2010to2019_v00.csvimport pandas as pd
df=pd.read_csv('Vancouver_weather2010to2019_v00.csv')
cols=df.columns
df1=df[cols[:10]]
df2=df[cols[10:]]
ll=len(df)
df3=df.head(5000)
df4=df.tail(ll-5000)
df.columns
Index(['Unnamed: 0','Longitude (x)','Latitude (y)','Station Name','Climate ID','Date/Time (LST)','Year','Month','Day','Time (LST)','Temp (°C)','Temp Flag','Dew Point Temp (°C)','Dew Point Temp Flag','Rel Hum (%)','Rel Hum Flag','Precip. Amount (mm)','Precip. Amount Flag','Wind Dir (10s deg)','Wind Dir Flag','Wind Spd (km/h)','Wind Spd Flag','Visibility (km)','Visibility Flag','Stn Press (kPa)','Stn Press Flag','Hmdx','Hmdx Flag','Wind Chill','Wind Chill Flag','Weather'],
dtype='object')