<jupyter_start><jupyter_text>Intro to Pandas***Following [this](http://pandas.pydata.org/pandas-docs/stable/10min.html) tutorial.<jupyter_code>%matplotlib inline
# Imports
import pandas as pd
import numpy as np
import matplotlib.pyplot as plt
from pylab import *

# Convenience imports
from IPython.display import display # display(your_stuff)
plot([1, 2, 3])<jupyter_output><empty_output><jupyter_text>Object Creation***<jupyter_code># Create a Series
s = pd.Series([1, 3, 5, np.nan, 6, 8])
s
# Create a DataFrame

# create dates separated into periods - which are just days
dates = pd.date_range('20130101', periods=6)
display(dates)

# create an arary: np.random.randn(6, 4) -> array(y, x) of random numbers
display(np.random.randn(6, 4))

# pd.DataFrame(row_values, index=row_names, columns=column_names)
df = pd.DataFrame(np.random.randn(6, 4), index=dates, columns=list('ABCD'))
display(df)
# create dataframe from a dictionary - {col_name: values}
#     >> np.array([[1, 2], [3, 4]], dtype="int32"): 
#        array([[3, 3, 3, 3],
#               [3, 3, 3, 3]], dtype=int32)
df2 = pd.DataFrame({ 'A' : 1.,
                     'B' : pd.Timestamp('20130102'),
                     'C' : pd.Series(1,index=list(range(4)),dtype='float32'),
                     'D' : np.array([3] * 4,dtype='int32'),
                     'E' : pd.Categorical(["test","train","test","train"]),
                     'F' : 'foo' })

print ("Dictionary representation:")
display(df2.to_dict())

print ("Data frame representation:")
display(df2)

print ("Check all data types:")
display(df2.dtypes)<jupyter_output><empty_output><jupyter_text>Viewing Data***<jupyter_code># see the top & bottom rows of the frame
print "Display all data frame:"
display(df)

print "Display top 2 rows:"
display(df.head(2))

print "Display bottom 3 rows:"
display(df.tail(3))
# display index (row_names), columns, and underlying numpy data
display(df.index)

display(df.columns)

display(df.values) 

display(df.describe())
# take actions on the data
print "Transpose (pivot) the data: "
display(df.T)

print "Sort the data: "
display(df)
display(df.sort_index(axis=1, ascending=False))
"""
    - Open a file with columns and rows
    - clean rows with particular values
    - reindex the data frame
    - add missing data for missing indexes
    - convert columns to list/dict
"""
import pandas as pd
import csv

data_file = open('/Users/whitehat/Desktop/facs_standard.txt', 'r')
file_name = os.path.basename(data_file.name).split('.')[0]

sniffer = csv.Sniffer()
dialect = sniffer.sniff(data_file.read().replace('\r', '\n'))
print (dialect.delimiter)
# returns ','
data_file.seek(0) # return to the beginning of the file

df = pd.read_csv(data_file, sep=dialect.delimiter)
antigens = df.columns[1:]
current_indexes = [int(line.split(":")[0]) for line in df['Sample'] if line not in ('Mean', 'StdDev')]
full_index = range(1, 97)

# ~df['column_name'].isin(some_values) == # df = df[df.Sample != 'Mean'] and df = df[df.Sample != 'StdDev']
df = df.loc[~df['Sample'].isin(['Mean', 'StdDev'])]
df.index += 1
df.index = current_indexes
df = df.reindex(full_index, fill_value=1)
result = {"{} - {}".format(file_name, antigen): list(df[antigen])  for antigen in antigens}
df
# Analyzing Chipotle Data
url = 'https://raw.githubusercontent.com/justmarkham/DAT8/master/data/chipotle.tsv'
df = pd.read_csv(url, sep='\t')
# df.head(10)
df = df[df.choice_description.notnull()]
df.item_price = df.item_price.str.replace('$', '')
df.item_price = df.item_price.astype(float)
df[df.item_price > 10].head()
df.describe()
df[['item_price', 'quantity']].plot(style=['o', 'rx'])
plt.scatter(df['item_price'], df['quantity'])
print('Unique Values: ', df['item_name'].unique())
print('Catagory Count: ', df['item_name'].value_counts())
df['item_price'].hist(bins=10)
df.boxplot(column='item_price', by='item_name')<jupyter_output><empty_output><jupyter_text>*** Loadn Predition Analysis<jupyter_code>training_set = 'data/loan_predict/train.csv'
df = pd.read_csv(training_set, sep=',')
plot(range(5))
df.head()<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.1732418524871355, 'fraction_numerical': 0.02058319039451115, 'mean_word_length': 4.8733812949640285, 'pattern_counts': {'":': 1, '<': 17, '<?xml version=': 0, '>': 21, 'https://': 1, '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': '4', 'dir': 'jupyter-structured-clean-dedup', 'id': '442238', 'license': 'MIT', 'n_tokens_mistral': 1535, 'n_tokens_neox': 1451, 'n_words': 330, 'path': '1t_DataAnalysisMLPython/1e_Pandas/Pandas_intro.ipynb', 'repo_name': 'yevheniyc/C', 'size': '4081'}