<jupyter_start><jupyter_text>06_02: Pandas DataFrames and Series<jupyter_code>import math
import collections

import numpy as np
import pandas as pd
import matplotlib.pyplot as pp

%matplotlib inline
pd.options.display.max_rows = 16
nobels = pd.read_csv('nobels.csv', names=['year','discipline','nobelist'])
nobels.info()
nobels.head()
nobels.tail()
len(nobels)
nobels.columns
nobels.dtypes
nobels.index
nobels['discipline']
nobels.nobelist
nobels.discipline.values[:50]
nobels.discipline.unique()
nobels.nobelist.value_counts()
# select rows by building a Boolean mask, and using it as fancy index
nobels[nobels.discipline == 'Physics']
# select rows by the string-expression-based query interface
nobels.query('discipline == "Chemistry"')
nobels['Curie' in nobels.nobelist]
# Series.str methods perform operations on Series values as strings;
# "contains" tests if a pattern is contained in each element;
# so we select the rows in which the field "nobelist" contains "Curie"

nobels[nobels.nobelist.str.contains('Curie')]
disco = np.load('discography.npy')
disco
disco_df = pd.DataFrame(disco)
disco_df
disco_df.dtypes
pd.DataFrame([{'title': '<NAME>', 'year': 1969},
              {'title': 'The Man Who Sold the World', 'year': 1970},
              {'title': '<NAME>', 'year': 1971}])
pd.DataFrame([('Ziggy Stardust', 1), ('Aladdin Sane', 1), ('Pin Ups', 1)], columns=['title','toprank'])
disco['title'], disco['release']
pd.DataFrame({'title': ['<NAME>', 'The Man Who Sold the World', '<NAME>',
                        'Ziggy Stardust', 'Aladdin Sane', 'Pin Ups', 'Diamond Dogs',
                        'Young Americans', 'Station To Station', 'Low', 'Heroes', 'Lodger'],
              'release': ['1969-11-14', '1970-11-04', '1971-12-17', '1972-06-16',
                          '1973-04-13', '1973-10-19', '1974-05-24', '1975-03-07',
                          '1976-01-23', '1977-01-14', '1977-10-14', '1979-05-18']})<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.1661554192229039, 'fraction_numerical': 0.06083844580777096, 'mean_word_length': 4.056847545219639, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 9, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '1', 'dir': 'jupyter-structured-clean-dedup', 'id': '457909', 'license': 'MIT', 'n_tokens_mistral': 757, 'n_tokens_neox': 659, 'n_words': 172, 'path': '06_02_dataframes.ipynb', 'repo_name': 'reemalamri/-Hail-VersionControl-workshop', 'size': '1974'}