<jupyter_start><jupyter_text>Pandas  pandas import<jupyter_code>import pandas as pd
import numpy as np<jupyter_output><empty_output><jupyter_text>create pandas Series<jupyter_code>a = pd.Series(np.array(100), dtype=int)
a<jupyter_output><empty_output><jupyter_text>create pandas Series with data type and index<jupyter_code>b = pd.Series([1,2,3,4], dtype=int, index=['a', 'b', 'c', 'd'])
b<jupyter_output><empty_output><jupyter_text>create pandas Series from dictionary<jupyter_code>data = {'a' : 0., 'b' : 1., 'c' : 2.}
s = pd.Series(data)
s<jupyter_output><empty_output><jupyter_text>get pandas data by index<jupyter_code>s[2]<jupyter_output><empty_output><jupyter_text>get pandas data by 'named' index<jupyter_code>s['c']<jupyter_output><empty_output><jupyter_text>create pandas from list, and set columns name<jupyter_code>data = [['Alex',10],['Bob',12],['Clarke',13]]
df = pd.DataFrame(data,columns=['Name','Age'])
df<jupyter_output><empty_output><jupyter_text>get pandas column names<jupyter_code>df.columns<jupyter_output><empty_output><jupyter_text>get pandas shape<jupyter_code>df.shape<jupyter_output><empty_output><jupyter_text>get pandas indexes<jupyter_code>df.index<jupyter_output><empty_output><jupyter_text>get pandas data by column names<jupyter_code>df[['Age', 'Name']]<jupyter_output><empty_output><jupyter_text>get pandas data by row indexes<jupyter_code>df.loc[1:]<jupyter_output><empty_output><jupyter_text>get pandas cell data by row/column<jupyter_code>df.loc[1]['Age']<jupyter_output><empty_output><jupyter_text>Read from csv file<jupyter_code>df_demo = pd.read_csv('demo.csv')<jupyter_output><empty_output><jupyter_text>print the data frame<jupyter_code>df_demo<jupyter_output><empty_output><jupyter_text>print the head rows<jupyter_code>df_demo.head()<jupyter_output><empty_output><jupyter_text>print the tail rows<jupyter_code>df_demo.tail()<jupyter_output><empty_output><jupyter_text>get one column<jupyter_code>df_demo['Mailbox']<jupyter_output><empty_output><jupyter_text>get part of the columns<jupyter_code>df_demo[['Mailbox', 'Notes ID']]<jupyter_output><empty_output><jupyter_text>data cleaning, process missing data<jupyter_code>df_demo.fillna('N', inplace=True)
df_demo<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.14221824686940965, 'fraction_numerical': 0.00849731663685152, 'mean_word_length': 14.753521126760564, 'pattern_counts': {'":': 0, '<': 81, '<?xml version=': 0, '>': 81, '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': '20', 'dir': 'jupyter-structured-clean-dedup', 'id': '547521', 'license': 'MIT', 'n_tokens_mistral': 918, 'n_tokens_neox': 889, 'n_words': 112, 'path': 'post/python/16-pandas-demo-1/pandas_demo.ipynb', 'repo_name': 'jerrywang1981/jerrywang1981.github.io', 'size': '2236'}