<jupyter_start><jupyter_text>---     Department of Data ScienceCourse: Tools and Techniques for Data Science---Instructor: <NAME>, Ph.D.     Lecture 3.9 (Pandas-01)  _From Python Dictionary to Pandas Dataframe.ipynb_  1. Overview of Pandas Library and its Datastructures  > **A Pandas Dataframe is a 2-dimensional labeled data structure (like SQL table) with heterogeneously typed columns, having both a row and a column index.**  Learning agenda of this notebook1. Overview of Pandas Library and its Data Structures2. Install Pandas Library3. Read Datasets into Pandas Dataframe4. Python Dictionaries vs Pandas Dataframes5. Anatomy of a Dataframe6. Bonus  2. Install Pandas Library<jupyter_code># To install this library in Jupyter notebook
import sys
!{sys.executable} -m pip install pandas --quiet
import pandas as pd
pd.__version__ , pd.__path__<jupyter_output><empty_output><jupyter_text>3. Read Data Sets into Pandas Dataframe  a. Titanic Dataset<jupyter_code>df_titanic = pd.read_csv('datasets/titanic3.csv')
df_titanic<jupyter_output><empty_output><jupyter_text>b. IMDB Dataset<jupyter_code>df_imdb = pd.read_csv('datasets/imdb.csv')
df_imdb<jupyter_output><empty_output><jupyter_text>c. Covid Dataset<jupyter_code>df_covid =pd.read_csv('datasets/covid-data.csv')
df_covid<jupyter_output><empty_output><jupyter_text>4. Python Dictionaries vs Pandas Dataframes<jupyter_code>person = {
    "name" : "Arif",
    "age" : 51,
    "address" : "Karachi",
    "cell" : "0320-431",
    "bg": "A-"
}
person
people = {
    "name" : ["Rauf", "Arif", "Maaz", "Hadeed", "Mujahid", "Mohid"],
    "age" : [52, 51, 26, 22, 18, 17],
    "address": ["Lahore", "Karachi", "Lahore", "Islamabad", "Kakul", "Karachi"],
    "cell" : ["321-123", "320-431", "321-478", "324-446", "321-967", "320-678"],
    "bg": ["B+", "A-", "B+", "O-", "A-", "B+"]
}
people
! cat datasets/people.csv
df_people = pd.read_csv('datasets/people.csv')
df_people<jupyter_output><empty_output><jupyter_text>**Accessing Elements of Dictionaries and Dataframes**<jupyter_code>people.get('age')
mylist = people['name']
mylist
type(mylist)
df_people[' age']
myseries = df_people['name']
myseries
type(myseries)
df_people.index
df_people.columns<jupyter_output><empty_output><jupyter_text>5. Anatomy of a Dataframe  6. Bonus (Changing display properties of a Dataframe Object)- Get the option names `pd.describe_option()`- Get current value of a display option `pd.get_option('nameofoption')`- Change value of a display option `pd.set_option('nameofoption', newvalue)`- Resetting options to default `pd.reset_option('all')<jupyter_code>df_covid<jupyter_output><empty_output><jupyter_text>a. Changing the number of columns to be displayed<jupyter_code>pd.describe_option()
pd.get_option('max_columns')
pd.set_option('max_columns', 67)
pd.get_option('max_columns')
df_covid<jupyter_output><empty_output><jupyter_text>b. Changing the number of rows to be displayed **Display 6 rows instead of default of 10**<jupyter_code>pd.get_option('min_rows')
pd.set_option('min_rows', 8)
pd.get_option('min_rows')
df_covid<jupyter_output><empty_output><jupyter_text>**Display 30 rows instead of default of 10**<jupyter_code>pd.set_option('min_rows', 30)
pd.get_option('min_rows')
df_covid<jupyter_output><empty_output><jupyter_text>>Students should check out the relationship of option `max_rows` with `min_rows` at your own  c. Changing Number of Characters to be Displayed in each Column<jupyter_code>df_imdb
pd.get_option('display.max_colwidth')
pd.set_option('display.max_colwidth', 200)
pd.get_option('display.max_colwidth')
df_imdb<jupyter_output><empty_output><jupyter_text>c. Setting the options back to default<jupyter_code>pd.reset_option('all')<jupyter_output><empty_output><jupyter_text>d. Changing Style by applying CSS to Pandas Dataframe<jupyter_code>df_titanic.head(10).style.set_table_styles(
[{'selector': 'th',
  'props': [('background', '#7CAE00'), 
            ('color', 'white'),
            ('font-family', 'verdana')]},
 
 {'selector': 'td',
  'props': [('font-family', 'verdana')]},

 {'selector': 'tr:nth-of-type(odd)',
  'props': [('background', '#DCDCDC')]}, 
 
 {'selector': 'tr:nth-of-type(even)',
  'props': [('background', 'white')]},
 
 {'selector': 'tr:hover',
  'props': [('background', 'pink')]},
 
]
).hide_index()<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.14854234150856085, 'fraction_numerical': 0.021980564553447476, 'mean_word_length': 6.3520408163265305, 'pattern_counts': {'":': 3, '<': 54, '<?xml version=': 0, '>': 56, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 1, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '13', 'dir': 'jupyter-structured-clean-dedup', 'id': '301266', 'license': 'BSL-1.0', 'n_tokens_mistral': 1653, 'n_tokens_neox': 1556, 'n_words': 359, 'path': 'data-science-master/Section-3-Python-for-Data-Scientists/Lec-3.09(Pandas-01-From-Python-Dictionary-to-Pandas-Dataframe).ipynb', 'repo_name': 'Hamid-Ali-99/Python_Just_Python', 'size': '4334'}