


Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
This page cannot be seen from the preview
Don't miss anything!



Department of Computer Science & Engineering,
Experiment No.: 1
Title: Write a program to import and export, clean and prepare the data.
Objectives:
Theory:
Once we have our data in Python, then we can perform all the subsequent data analysis procedures we need. Data acquisition is a process of loading and reading data into notebook from various sources. To read any data using Python‟s pandas package, there are two important factors to consider: format and file path. Format is the way data is encoded. We can usually tell different encoding schemes by looking at the ending of the file name. Some common encodings are csv, json, xlsx, hdf and so forth. The (file) path tells us where the data is stored. Usually it is stored either on the computer we are using, or online on the internet. A large number of properties are associated with each data point. Because the properties are separated from each other by commas, we can guess the data format is CAV, which stands for Comma Separated Values. At this point, these are just numbers and don‟t mean much to humans, but once we read in this data, we can try to make more sense out of it. In pandas, the “read_csv()” method can read in files with columns separated by commas into a pandas DataFrame. Reading data in pandas can be done quickly in three lines.
Department of Computer Science & Engineering,
head() method introduced to check the dataset, we see the correct headers inserted at the top of each column. At some point in time after you‟ve done operations on your dataframe, you may want to export your pandas dataframe to a new CSV file. You can do this using the method, ”to_csv()". To do this, specify the file path (which includes the filename) that you want to write to. For example, if you would like to save the dataframe "df" as "automobile.csv" to your own computer, you can use the syntax: df.to_csv ("automobile.csv"). This shows how to read and save csv files. However, pandas also supports importing and exporting of most data filetypes with different dataset formats. The code syntax for reading and saving other data formats is very similar to read or save csv file. Data pre-processing is a necessary step in data analysis. It is the process of converting or mapping data from one “raw” form into another format to make it ready for further analysis. Data pre-processing is also often called “data cleaning” or “data wrangling”, and there are likely other terms. Here are the topics that we‟ll be covering in this experiment: First, we‟ll show you how to identify and handle missing values. A “missing value” condition occurs whenever a data entry is left empty. Then, we‟ll cover data formats. Data from different sources may be in various formats, in different units or in various conventions. We will introduce some methods in Python pandas that can standardize the values into the same format, or unit, or convention. After that, we‟ll cover data normalization. Different columns of numerical data may have very different ranges, and direct comparison is often not meaningful. Normalization is a way to bring all data into a similar range, for more useful comparison. Specifically, we‟ll focus on the techniques of centering and scaling. And then, we‟ll introduce data binning. Binning creates bigger categories from a set of numerical values. It is particularly useful for comparison between groups of data. And lastly, we‟ll talk about categorical variables and show you how to convert categorical values into numeric variables to make statistical modeling easier. In Python, we usually perform operations along columns; each row of the column represents a sample, i.e., a different used car in the database. You access a column by specifying the name of the column. For example, you can access "symbolling” and “body-style”; each of these columns is a pandas series. When nodata value is stored for a feature for a particular observation, we say this feature has a “missing value”. Usually “missing value: in dataset” appears as “?”, “N/A”, 0 or just a blank cell. In the example here, the “normalized-losses” feature has a “missing value”, which is represented with NaN. But how can you deal with missing data? There are many ways to deal with missing values, and this is regardless of Python, R, or whatever tool you use. Of course, each situation is different and should be judged differently. However, these are the typical options you can consider:
Department of Computer Science & Engineering,
containing missing values. And then we learned how to replace missing values with other values. But don‟t forget the other ways to deal with missing data: you can always check for a higher quality dataset or source. Or, in some cases, you may want to leave the missing data as missing data.
Key concepts: Data Cleaning, Data Pre-processing
Algorithm:
Read data set in Pandas Dataframe Change the default header in DataFrame. Replace missing values with constant or values specified Replace missing values with mean Replace missing values with mode Replace the missing values with imputed values based on the other characteristics of the record Export pre-processed dataset in CSV or other formats