<jupyter_start><jupyter_text>Pandas and Matplotlib- Introduction to Pandas- Pandas Series, Data Frames,Indexing/Slicing for Data Frames- Basic Operations With Data frame,Renaming Columns, filtering a data frame. - sort and merging dataframes- Importing external data to DataFrame- Matplotlib - Introduction,plot(),Controlling Line Properties,Working with Multiple Figures,Histograms  Series<jupyter_code>import pandas as pd
import numpy as np
import matplotlib.pyplot as plt
a = [1,2,3,4,5]
s = pd.Series(a)
s
a = {"A":1,"B":2,"C":3}
s = pd.Series(a)
s
a = [1,2,3,4,5]
s = pd.Series(a,index=[11,12,13,14,15])
s
a = [1,2,3,4,5]
s = pd.Series(a,index=[11,12,13,14,15],dtype="int8")
s
a = [1,2,3,4,5]
s = pd.Series(a,index=(11,12,13,14,15),dtype=np.int32)
s
a = {"A":1,"B":2,"C":3}
s = pd.Series(a,index = ["A","C","E"],dtype=np.int32)
print(a)
print(s)<jupyter_output>{'A': 1, 'B': 2, 'C': 3}
A    1.0
C    3.0
E    NaN
dtype: float64<jupyter_text>Indexing and slicing<jupyter_code>a = [1,2,3,4,5]
s = pd.Series(a,index=(11,12,13,14,15),dtype=np.int32)
s
s[12]<jupyter_output><empty_output><jupyter_text>DataFrame<jupyter_code>a = np.random.randint(1,20,18).reshape(6,3)
df = pd.DataFrame(a)
df
a = np.random.randint(1,20,18).reshape(6,3)
df = pd.DataFrame(a,columns=["A","B","C"])
df<jupyter_output><empty_output><jupyter_text>some attributes<jupyter_code>df.keys()
df.columns
list(df.index)
df.values
df.size # Size will return total number of elements including NaN
df.count() # # Count will return total number of elements excluding NaN<jupyter_output><empty_output><jupyter_text>Indexing and slicing<jupyter_code>df
df.A
df["A"]
df[["B","A","C"]]<jupyter_output><empty_output><jupyter_text>access row<jupyter_code>df.loc[0]
df.loc[[0,4]]
df.loc[[0,4],'A']
df.loc[[0,4],['A',"C"]]
df.loc[:,["A","C"]]<jupyter_output><empty_output><jupyter_text>iloc (index based location)<jupyter_code>df
df.iloc[0,0]
df.iloc[-1,0]
df.iloc[:3,::]
df.iloc[:,[0,2]]<jupyter_output><empty_output><jupyter_text>Matplotlib<jupyter_code>import matplotlib.pyplot as plt
a = np.random.randint(1,100,60).reshape(20,3)
df = pd.DataFrame(a,columns=["A","B","C"])
df<jupyter_output><empty_output><jupyter_text>Line plot<jupyter_code>plt.figure(figsize=(16,4))
plt.plot(range(20),df.A)
plt.plot(range(20),df.B)
plt.plot(range(20),df.C)
plt.show()
plt.figure(figsize=(16,4))
plt.plot(range(20),df)
plt.show()
plt.figure(figsize=(16,4))
# plt.plot(range(20),df.A,color="r")
plt.plot(range(20),df.B,"--b")
plt.plot(range(20),df.A,"-r")
plt.show()<jupyter_output><empty_output><jupyter_text>scatter plot<jupyter_code>plt.figure(figsize=(16,4))
plt.scatter(range(20),df.B,c="r",marker="d")
plt.show()<jupyter_output><empty_output><jupyter_text>Bubble chart<jupyter_code>plt.figure(figsize=(16,4))
for idx in range(df.B.size):
    #plt.scatter(idx,df["B"][idx],c="r")
#     plt.scatter(idx,df["B"][idx],s=.2*np.pi*df["B"][idx]*df["B"][idx]) # s = 3.14*r2
    plt.scatter(idx,df["B"][idx],s=20*df["B"][idx],alpha=.4) # s = 3.14*r2
plt.show()<jupyter_output><empty_output><jupyter_text>Write labels to points<jupyter_code>plt.figure(figsize=(16,4))
for idx in range(df.B.size):
    if df["B"][idx] >=80:
        plt.scatter(idx,df["B"][idx],s=20*df["B"][idx],marker="*",color="r")    
        plt.text(idx+.5,df["B"][idx]+2,(idx,df["B"][idx]))
    else:
        plt.scatter(idx,df["B"][idx],s=20*df["B"][idx],alpha=.4)    
plt.show()
plt.figure(figsize=(16,4))
for idx in range(df.B.size):
    if df["B"][idx] >=80:
        plt.scatter(idx,df["B"][idx],s=20*df["B"][idx],marker="*",color="r")    
        plt.text(idx+.5,df["B"][idx]+2,(idx,df["B"][idx]))
    elif df["B"][idx] <80 and df["B"][idx] >=40:
        plt.scatter(idx,df["B"][idx],s=5*df["B"][idx],alpha=.4,marker="D")    
    else:
        plt.scatter(idx,df["B"][idx],s=20*df["B"][idx],alpha=.4,marker="^")    

plt.show()<jupyter_output><empty_output><jupyter_text>bar chart<jupyter_code>plt.figure(figsize=(16,4))
plt.bar(range(20),df.B,color="r")
plt.show()
plt.figure(figsize=(16,4))
plt.bar(range(20),df.B,color="r")
plt.plot(range(20),df.B,color="r")
plt.stem(range(20),df.B,color="c")
plt.show()<jupyter_output><empty_output><jupyter_text>labels,legend and titles<jupyter_code>plt.figure(figsize=(16,4))
for idx in range(df.B.size):
    plt.bar(idx,df["B"][idx],color="b")    
    plt.text(idx,df["B"][idx]+1,df["B"][idx])
plt.show()
plt.figure(figsize=(16,4))
plt.bar(range(20),df["A"],color="c",label="A bar")
plt.bar(range(20),df["B"],color="m",label="B bar")
plt.bar(range(20),df["C"],color="r",label="C bar")
plt.legend()
plt.xlabel("X-axis")
plt.ylabel("Y-axis")
plt.title("Bar graph")
plt.xticks(range(20))
plt.yticks(range(0,100,5))
plt.show()<jupyter_output><empty_output><jupyter_text>Histogram<jupyter_code>a = np.random.randint(1,100,500)
plt.hist(a,rwidth=.9)
plt.show()
a = np.random.randint(1,100,500)
plt.hist(a,bins=20,rwidth=.9)
plt.xticks(range(0,100,5))
plt.show()
df.A.plot(kind="line")
plt.show()
df.A.plot(kind="hist")
plt.show()
df.A.plot(kind="box")
plt.show()
plt.boxplot(df.A)
plt.show()
df.plot(kind="box")
plt.show()
df["A"][0] = 300
df.A.plot(kind="box")
plt.show()<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.24113200232603219, 'fraction_numerical': 0.05039736383019965, 'mean_word_length': 7.403908794788274, 'pattern_counts': {'":': 6, '<': 61, '<?xml version=': 0, '>': 63, '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': '15', 'dir': 'jupyter-structured-clean-dedup', 'id': '245124', 'license': 'MIT', 'n_tokens_mistral': 2509, 'n_tokens_neox': 2345, 'n_words': 279, 'path': '19_Pandas_Matplotlib.ipynb', 'repo_name': 'akash0905/Python_codes', 'size': '5159'}