DataFrames
Essentially multiple series stitched to each other, note they must have the same index
Create DataFrame
# note we have a np 3x3 array - mydata
myindex = ['UK', 'USA', 'CA']
mycol = ['Jan', 'Feb', 'Mar']
df = pd.DataFrame(data=mydata, index=myindex, columns=mycol)
Read CSV
df = pd.read_csv('fileLocation.csv')
# parse_dates=[0], turns col 0 into dates objMethods
df.columns # a list of the col names
df.index # returns the start index and the last index, along with the step size
df.head(n) # returns the first n rows
df.tail(n)
df.info() # returns info on the dataframe
df.shape() # returns the shaps of the dataframe
df.describe() # returns a table of info for the numeric data
df.describe().transpose() # puts the table on its sideCols
### select
df['colName'] # selects colName
df[['colName1', 'colName2']]
### new col
df['newCol'] = df['colName'] + df['colName2']
### remove col axis=0(row) axis=1(col)
df.drop('colName', axis=1, inplace=true) # inplace=true, perm deletes it
# better method, since it is not perm deleted
df = df.drop('colName', axis=1)Rows
df.set_index('col_name') # Note: col values must be unique, note not inplace
df.reset_index()
df.iloc[0:4] # index location
df.loc[['named index', 'another index']] # index location
# drop row
df.drop(1, axis=0) # note if labeled you need to use the label
# add new row
df.append(row)