<SYSTEM_TASK:>
Given the following text description, write Python code to implement the functionality described below step by step
<END_TASK>
<USER_TASK:>
Description:
 Pandas
"pandas" is a Python package providing fast, flexible, and expressive data structures designed to make working with “relational” or “labeled” data both easy and intuitive. It aims to be the fundamental high-level building block for doing practical, real world data analysis in Python. Additionally, it has the broader goal of becoming the most powerful and flexible open source data analysis / manipulation tool available in any language. It is already well on its way toward this goal.
The convention is to import pandas and set "pd" as its package alias.
Step1:  1-D series
Step2:  DataFrame
Step3:  Data types
Step4:  converting types
If you try to "cast" the value for Slovenia, you will get an error
eu['Slovenia'].astype('float')
This is due to an empty "n/a" value.
missing values
Let's re-read the dataset setting expected "na" values
Step5:  Filtering with Pandas
Step6:  Creating a new index not on the values but on the 2 letter geo-code column
Step7:  Row index with "iloc" method
<ASSISTANT_TASK:>
Python Code:
import pandas as pd
Explanation: Pandas
"pandas" is a Python package providing fast, flexible, and expressive data structures designed to make working with “relational” or “labeled” data both easy and intuitive. It aims to be the fundamental high-level building block for doing practical, real world data analysis in Python. Additionally, it has the broader goal of becoming the most powerful and flexible open source data analysis / manipulation tool available in any language. It is already well on its way toward this goal.
The convention is to import pandas and set "pd" as its package alias.
End of explanation
s = pd.Series([3, 5, 67, 2, 4])
s
s.name = "OneDArray"
s
s.index
s.values
s.sum()
s.min()
s.count()
s * 3
s.sort_values()
s.value_counts()
s.abs?
Explanation: 1-D series
End of explanation
eu = pd.read_csv('data/eu_revolving_loans.csv',
                header=[1,2,3], index_col=0, skiprows=1)
eu.tail(4)
eu.index
eu.columns
eu.shape
eu.min(axis=1)
eu.min()
eu * 3
%pylab inline
eu.plot(legend=False)
Explanation: DataFrame
End of explanation
eu.dtypes
Explanation: Data types: dtypes
DataFrame is built on Numpy -- and uses the same data type representations.
End of explanation
eu = pd.read_csv('data/eu_revolving_loans.csv',
                 header=[1,2,3],
                 index_col=0,
                 skiprows=1,
                 na_values=['-'])
eu.dtypes
Explanation: converting types
If you try to "cast" the value for Slovenia, you will get an error
eu['Slovenia'].astype('float')
This is due to an empty "n/a" value.
missing values
Let's re-read the dataset setting expected "na" values:
End of explanation
trade = pd.read_csv('data/ext_lt_intratrd.tsv', sep='\t')
trade.dtypes
trade.columns
# expect an key error below due to extra spaces in names
trade['2013']
new_cols = dict([(col, col.strip()) for col in trade.columns])
new_cols
trade.rename(columns=new_cols)
trade = trade.rename(columns=new_cols)
trade['2013']
# selecting row 3
trade.ix[3]
# selecting all rows where column index = 0
trade.ix[:,0]
# split out the column with index 0 & assign to new column 'geo'
# representing the country 2 letter code
trade['geo'] = trade.ix[:,0].map(lambda row: row.split(',')[-1])
trade['geo'].head()
trade['geo'].isin(['UK', 'DE'])
trade[trade['geo'].isin(['UK', 'DE'])]
# boolean selecting with more complex boolean expressions
# - find all countries where there are continuous growth from 2012-2014
trade[(trade['2014'] > trade['2013']) & 
      (trade['2013'] > trade['2012'])]
# create a column that represents those with increase from 2012 - 2013
trade['2013inc'] = trade['2013'] > trade['2012']
trade['2013inc'].head()
Explanation: Filtering with Pandas
End of explanation
trade = trade.set_index('geo')
# now filter based on the geo column
trade.loc['DE']
Explanation: Creating a new index not on the values but on the 2 letter geo-code column
End of explanation
# now filter based on row index for the top 100 rows
trade.iloc[:100]
Explanation: Row index with "iloc" method
End of explanation
<END_TASK>