12. Python - Pandas - Basics

 Importing Pandas:

import pandas as pd


Types of core objects in Pandas:

DataFrames // a table like excel worksheet. Has index for rows, column headers, and values

Series // A list of values


Creating a Data Frame:

pd.DataFrame( { 'COLUMNNAME_1' : [VALUE,VALUE] , 'COLUMNNAME_2' : [VALUE] } )

// just like a map, has a key and values (which are lists of items)

// index are automatically created from 0...nROWs


pd.DataFrame( { 'COLUMNNAME_1' : [VALUE,VALUE] , 'COLUMNNAME_2' : [VALUE] },

index = [ ' FIRST ', ' SECOND '] )

// including a index property allows naming indexes ourselves


Creating a Series:

pd.Series( [VALUE,VALUE,VALUE] , index = [ 'A' , ' B ' , ' C ' ], name = 'MYSERIES' )

// creates a series with list of values, naming our index, and then giving the series an overall name

// Data Frames is like a bunch of series glued together.


Basic Methods:

data_frame.head() // shows first couple rows

data_frame.describe() // summarize data with some statistics (MEAN, MAX,MIN, ETC)

data_frame.columns // lists out column headers


Reading Files:

variable = pd.read_csv(PATH)

variable = pd.read_xlsv(PATH)

// more


Saving Files:

data_frame.to_csv(PATH)

data_frame.to_xlsv(PATH)


Creating Sub Data Frames:

features = ['A','B','C'] // choose columns wanted

new_data_frame = data_frame[features]


Comments

Popular posts from this blog

2. FreeCodeCamp - Dynamic Programming - Learn to Solve Algorithmic Problems & Coding Challenges

20. Data Analytics - Analyze Data to Answer Questions - Week 1

3. Algorithms - Selection Sort