<jupyter_start><jupyter_text>Describe Data<jupyter_code># Attribute
car_sales.dtypes
car_sales.columns
car_columns = car_sales.columns
car_columns
car_sales.index
car_sales
car_sales.describe()
car_sales.info()
car_sales.mean()
car_prices = pd.Series([3000,1500,1230])
car_prices.mean()
car_sales.sum()
car_sales['Doors'].sum()
car_sales.std()
len(car_sales)
car_sales.shape<jupyter_output><empty_output><jupyter_text>Viewing and Selecting Data<jupyter_code>car_sales.head()
car_sales.head(2)
# .loc and .iloc
animals = pd.Series(["cat",'bird','panda','snake','dog'],index=[0,3,6,3,9])
animals
animals.loc[3]
animals.loc[9]
car_sales
car_sales.loc[3]
# .iloc
animals.iloc[3]
animals.iloc[:3]
car_sales.iloc[:3]
car_sales['Make']
car_sales['Colour']
car_sales.Make
car_sales[car_sales['Make'] == 'Toyota']
car_sales[car_sales['Odometer (KM)'] > 100000]
pd.crosstab(car_sales['Make'], car_sales['Doors'])
car_sales.groupby(['Make']).mean()
 car_sales['Odometer (KM)'].plot()
car_sales['Odometer (KM)'].hist()
car_sales["Price"] = car_sales["Price"].str.replace('[\$\,]|\.\d*', '').astype(int)
car_sales
car_sales['Price'].plot()
car_sales['Price'].hist()<jupyter_output><empty_output><jupyter_text>Manupalating Data<jupyter_code>car_sales['Make'] = car_sales['Make'].str.lower()
car_sales['Make']
car_sales
car_sales_missing = pd.read_csv('car-sales-missing-data.csv')
car_sales_missing
car_sales_missing['Odometer'].fillna(car_sales_missing['Odometer'].mean())
car_sales_missing
car_sales_missing['Odometer'].fillna(car_sales_missing['Odometer'].mean(), inplace=True)
car_sales_missing
car_sales_missing = car_sales_missing.dropna()
car_sales_missing
car_sales_missing.to_csv('car-sales-missing-dropped.csv')
car_sales_missing
# Column from series
seats_column = pd.Series([5,5,5,5,5])

# New column called seats
car_sales['Seats'] = seats_column 
car_sales
car_sales['Seats'].fillna(5,inplace=True)
car_sales
# Column from list
fuel_economy = [7.1,2.3,6.7,8.9,4.6,7.1,2.3,6.7,8.9,4.6]
car_sales['Fuel per 100KM'] = fuel_economy
car_sales
car_sales['Total fuel used (L)'] = (car_sales['Odometer (KM)']/100 * car_sales['Fuel per 100KM'])
car_sales
# create column from single value
car_sales['No of Wheels'] = 4
car_sales
car_sales['Passed Road Safety'] = True
car_sales
car_sales.drop('Total fuel used (L)', axis=1, inplace=True)
car_sales
car_sales_shuffles =  car_sales.sample(frac=1)
car_sales_shuffles
# only select 20% of the dataset
car_sales_shuffles.sample(frac=0.2)
car_sales_shuffles
car_sales_shuffles.reset_index(drop=True,inplace=True)
car_sales_shuffles
car_sales
car_sales.reset_index(drop=True,inplace=True)
car_sales
car_sales['Odometer (KM)'] = car_sales['Odometer (KM)'].apply(lambda x : x /1.6)
car_sales
car_sales.drop('Odometer (KN)', axis=1,inplace=True)
car_sales<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.1640625, 'fraction_numerical': 0.026633522727272728, 'mean_word_length': 9.31868131868132, 'pattern_counts': {'":': 0, '<': 13, '<?xml version=': 0, '>': 14, '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': '3', 'dir': 'jupyter-structured-clean-dedup', 'id': '162254', 'license': 'MIT', 'n_tokens_mistral': 1252, 'n_tokens_neox': 1123, 'n_words': 161, 'path': 'introduction-to-pandas.ipynb', 'repo_name': 'dulajkavinda/pandas-exploring-data-ML', 'size': '2816'}