<jupyter_start><jupyter_text>welcome to pandas world for datascience i'm dawit mamo your master<jupyter_code>import pandas as pd
# pandas two basic data types :
# 1: series which is 1 dimensional datatype
# example
series = pd.Series(["signal processing","computer vision","artificial intilegence"])
series
profision = pd.Series(["engineer","ece","computer_engineer"])
profision
# 2: dataframe which is two dimensional
#example  DataFrame is like python libray
data = pd.DataFrame({"fields":series,"profisional":profision})
data<jupyter_output><empty_output><jupyter_text>importing data from csv<jupyter_code>car_datas = pd.read_csv("car-sales.csv")
car_datas<jupyter_output><empty_output><jupyter_text>in pandas datframe axis 0 is row and axis 1 is colum<jupyter_code># exporting data using .to_csv
car_datas.to_csv("new_data_car_sales.csv",index=False)

new_data = pd.read_csv("new_data_car_sales.csv")
new_data
# to avoid double index valu under unnamed column use index = false in exporting<jupyter_output><empty_output><jupyter_text>describing Data<jupyter_code>#attributes
car_datas.dtypes
car_datas.columns
car_datas_column = car_datas.columns
car_datas_column
car_datas.index
# function 
car_datas.describe()  # describe() is a function
car_datas.info()
car_datas.mean()
car_datas.sum()
car_datas["Doors"].sum()
car_datas["Price"].sum()
len(car_datas)
car_datas
my_data = pd.Series([300,400,500])
my_data
my_data.mean()
my_data.sum()<jupyter_output><empty_output><jupyter_text>viewing and selecting data<jupyter_code># function head() to see some of the datas
# function tail() used to see the bottom of the dataframe
car_datas.head(7)
car_datas.tail()<jupyter_output><empty_output><jupyter_text>loc and iloc<jupyter_code># example
animal = pd.Series(["dog","cow","cat","panda"]) # with index of [0]
animal
animal = pd.Series(["dog","cow","cat","panda"],index = [0, 3, 2, 3])
animal
animal.loc[3]  # to see the location of specified index
animal.iloc[3]    # it refer to position
car_datas.loc[3]
car_datas.iloc[ :4]
car_datas.loc[ :4]
# selection of column .column_name = ["column_name"]
#car_datas["Make"]
car_datas.Colour
# but not for all types of data type 
#car_datas.Odometer (KM)  # WILL NOT WORK
car_datas["Odometer (KM)"]
car_datas[car_datas["Colour"] == "White"]  # selecting by colour  alwayes use [] for view and selection
car_datas[car_datas["Make"] == "Nissan"]
car_datas[car_datas["Make"], car_datas["Colour"] == "Nissan","Blue"]  # this is a problem but using crosstap
#pd.crosstab(car_datas["Make"] == "Nissan",car_datas["Colour"] == "White" )
pd.crosstab(car_datas["Make"] ,car_datas["Colour"] )<jupyter_output><empty_output><jupyter_text>groupby<jupyter_code>car_datas.groupby(["Make"]).mean() # groupby is a function
car_datas.groupby(["Colour"]).mean()<jupyter_output><empty_output><jupyter_text>plot<jupyter_code>car_datas["Odometer (KM)"].plot()
# if plot does't show up then 
# %matplotlib inline
# import matplotlib.pyplot as plt
# plot histogram  hist
car_datas["Odometer (KM)"].hist()
car_datas.Price.dtype  # dtype for datatypes
# to change price data in to integer
# replace 
car_datas
car_datas["Price"] = car_datas["Price"].str.replace('[\$\,\.]', '').astype(int)
car_datas
car_datas["Price"].plot()
car_datas["Price"].hist()
# in above conversion it included .00 to numbers so how to fix it<jupyter_output><empty_output><jupyter_text>manuplating Data<jupyter_code># data in lower case in string using str.lower()  title()
car_datas["Make"].str.title()
car_datas["Make"] = car_datas["Make"].str.lower()
car_datas<jupyter_output><empty_output><jupyter_text>filling the missing data<jupyter_code>car_sale_missing = pd.read_csv("car-sales-missing-data.csv")
#car_sale_missing["Odometer (KM)"].fillna(car_sale_missing["Odometer (KM)"].mean())
#car_sale_missing["Odometre (KM)"] = car_sale_missing["Odometer (KM)"].fillna(car_sale_missing["Odometer (KM)"].mean())
car_sale_missing
car_sale_missing["Odometer (KM)"].fillna(car_sale_missing["Odometer (KM)"].mean(),inplace=True)
car_sale_missing<jupyter_output><empty_output><jupyter_text>fillna is working with inplace=True<jupyter_code># to remove a value with NAN using dropna(inplace=True)
car_sale_missing.dropna(inplace=True)
car_sale_missing
car_sale_missing
car_sale = pd.read_csv("car-sales-missing-data.csv")
car_sale
# to save to new data store
new_car_sale = car_sale.dropna()
new_car_sale.to_csv("new_car_sale_drop.csv")
data = pd.read_csv("new_car_sale_drop.csv")
data<jupyter_output><empty_output><jupyter_text>adding data<jupyter_code>colum_seats = pd.Series([5,5,5,5,5])  # adding column with Series([])
data["seats"] = colum_seats
data
data["seats"].fillna(5,inplace=True)
data
# using python list
data = pd.read_csv("new_car_sale_drop.csv")
feul_economy = [4.2,5.5,2.3,1.2,2.6,3.9,7.8,41.2,5.6]    # using list python data length should be equal with the existing
data["Feul_cost"] = feul_economy
data
# creat new data from existing by operation
data["Total fuel used"] = data["Odometer (KM)"]/100 * data["Feul_cost"]
data
# create colum from a single number
data["Number of wheel"] = 4
data
# to delete column
data = data.drop("Number of wheel",axis=1) # axis 1 is column axis 0 is row
data<jupyter_output><empty_output><jupyter_text>sampling data<jupyter_code>data
s_data = data.sample(frac=1)
s_data
# 50 % of data
data_p = data.sample(frac=0.5)
#data.reset_index()  to get back to original index
data.reset_index(drop=True, inplace=True)
data
data["Odometer (KM)"] = data["Odometer (KM)"].apply(lambda x: x/1.6)
data   
# ctrl + enter for reset cells<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.14088793412101683, 'fraction_numerical': 0.011815252416756176, 'mean_word_length': 7.582181259600614, 'pattern_counts': {'":': 2, '<': 53, '<?xml version=': 0, '>': 53, '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': '13', 'dir': 'jupyter-structured-clean-dedup', 'id': '85833', 'license': 'Apache-2.0', 'n_tokens_mistral': 2182, 'n_tokens_neox': 2041, 'n_words': 442, 'path': 'wel_come_to_pandas.ipynb', 'repo_name': 'dawitmamo/ds_and_ML', 'size': '5586'}