# import the pandas package
import pandas as pd

# load in the dataset and save it to brics var.
brics = pd.read_csv("C:/Users/pySag/Documents/GitHub/Computer-Science/Courses/DAT-208x/Datasets/BRICS_cummulative.csv")

brics

# we can make the table look more better, by adding a parameter index_col = 0
brics = pd.read_csv("C:/Users/pySag/Documents/GitHub/Computer-Science/Courses/DAT-208x/Datasets/BRICS_cummulative.csv", index_col=0)

brics #notice how the indexes assigned to row observation are now deprecated.

"""
Explanation: Table of Content


Overviw


Accessing Rows


Element Access


Lab



Overview:
Being a data scientist means, we gotta have to work with "big" data with different types.
We've seen how 2D Numpy arrays gives us power to compute data in a much efficient way, but the only downside to it is, they must be of the same type.
To solve this issue, ther's where the Pandas package comes in. So what's in Pandas?


High-level data manupalation.


The concept of "Data Frames" objects.

Data is stored in such data frames.



More specifically, they are tables,


with "rows" represented as "observations".


"Coloumns" represented by "variables".


Each row has a unique label, same goes for coloumns as well.


Coloumns can have different types.




We typically don't make data frames manually.


We convert .csv (Comma seperated values) files to data frames.


We do this importing the pandas package:


import pandas as pd, again pd is an "alias".

Now we can use a built-in function that comes packaged with pandas called as:

read_csv(&lt;path to .csv file)>



Example:
We will be using pandas package to import, read in the "brics dataset" into python, let's look how the dataframes look like:
End of explanation
"""


# Add a new coloumn
brics["on_earth"] = [ True, True, True, True, True ]

# Print them
brics

# Manupalating Coloumns
"""Coloumns can be manipulated using arithematic operations
on other coloumns"""

"""
Explanation: One of the most effective use of pandas is the ease at which we can select rows and coloumns in different ways, here's how we do it:


To access the coloumns, there are three different ways we can do it, these are:

data_set_var[ "coloumn-name" ]
&lt; data_set_var &gt;.&lt; coloumn-name &gt;



We can add coloumns too, say we rank them:
&lt;data_set_var&gt;["new-coloumn-name"] = &lt; list of values &gt;
End of explanation
"""


"""
# Import pandas as pd
import pandas as pd

# Import the cars.csv data: cars
cars = pd.read_csv("cars.csv")

# Print out cars
print(cars)
"""

"""
Explanation: Accessing Rows:

Syntax: dataframe.loc[ &lt;"row name"&gt; ]

Go to top:TOC
Element access

To get just one element in the table, we can specify both coloumn and row label in the loc().
Syntax: 


dataframe.loc[ &lt;"row-name, coloumn name"&gt; ]


dataframe[ &lt;"row-name"&gt; ].loc[ &lt;"coloumn-name"&gt; ]

dataframe.loc[ &lt;"rowName'&gt; ][&lt; "coloumnName" &gt;]

Lab:

Objective:


Practice importing data into python as Pandas DataFrame.


Practise accessig Row and Coloumns



Lab content:


CSV to DataFrame1


CSV to DataFrame2


Square Brackets


Loc1


Loc2



Go to:TOC
CSV to DataFrame1

Preface:
The DataFrame is one of Pandas' most important data structures. It's basically a way to store tabular data, where you can label the rows and the columns.
In the exercises that follow, you will be working wit vehicle data in different countries. Each observation corresponds to a country, and the columns give information about the number of vehicles per capita, whether people drive left or right, and so on. This data is available in a CSV file, named cars.csv. It is available in your current working directory, so the path to the file is simply 'cars.csv'.
To import CSV data into Python as a Pandas DataFrame, you can use read_csv().
Instructions:


To import CSV files, you still need the pandas package: import it as pd.


Use pd.read_csv() to import cars.csv data as a DataFrame. Store this dataframe as cars.


Print out cars. Does everything look OK?
End of explanation
"""


"""
# Import pandas as pd
import pandas as pd

# Import the cars.csv data: cars
cars = pd.read_csv("cars.csv", index_col=0)

# Print out cars
print(cars)
"""

"""
Explanation: CSV to DataFrame2

Preface:
We have a slight of a problem, the row labels are imported as another coloumn, that has no name.
To fix this issue, we are goint to pass an argument index_col = 0 to read_csv(). This is used to specify which coloumn in the CSV file should be used as row label?
Instructions:


Run the code with Submit Answer and assert that the first column should actually be used as row labels.


Specify the index_col argument inside pd.read_csv(): set it to 0, so that the first column is used as row labels.


Has the printout of cars improved now?



Go to top:TOC
End of explanation
"""


"""
# Import cars data
import pandas as pd
cars = pd.read_csv('cars.csv', index_col = 0)

# Print out country column as Pandas Series
print( cars['country'])

# Print out country column as Pandas DataFrame
print( cars[['country']])
"""

"""
Explanation: Square Brackets

Preface
Selecting coloumns can be done in two way.


variable_containing_CSV_file['coloumn-name']


variable_containing_CSV_file[['coloumn-name']]


The former gives a pandas series, whereas the latter gives a pandas dataframe.
Instructions:


Use single square brackets to print out the country column of cars as a Pandas Series.


Use double square brackets to print out the country column of cars as a Pandas DataFrame. Do this by putting country in two square brackets this time.
End of explanation
"""


"""
# Import cars data
import pandas as pd
cars = pd.read_csv('cars.csv', index_col = 0)

# Print out observation for Japan
print( cars.loc['JAP'] )

# Print out observations for Australia and Egypt
print( cars.loc[ ['AUS', 'EG'] ])
"""

"""
Explanation: Loc1

With loc we can do practically any data selection operation on DataFrames you can think of.
loc is label-based, which means that you have to specify rows and coloumns based on their row and coloumn labels.
Instructions:


Use loc to select the observation corresponding to Japan as a Series. The label of this row is JAP. Make sure to print the resulting Series.


Use loc to select the observations for Australia and Egypt as a DataFrame.
End of explanation
"""


