13 Lecture Student
13 Lecture Student
• read_csv file automatically understood that our CSV file had a header (“Name”, “Grade” and
“Age”).
If your file does not have a header, you can call read_csv with the header parameter set to None
as follows: pd.read_ csv(filename, header=None).
• read_csv read all columns in the CSV file. If you wish to load only some of the columns
(e.g. ‘Name’, ‘Age’ in our example), you can relay this using the usecols parameter as follows:
pd. read_csv (filename, usecols=[ 'Name', 'Age']).
Data handling & analysis with Pandas
2. Convert Python data into a DataFrame
Data handling & analysis with Pandas
Pandas provides functions for sorting (using .sort_values() function), finding the maximum or the minimum (using .max() or
.min() functions) or finding the largest or smallest n values (using .nsmallest() or .nlargest() functions
Data handling & analysis with Pandas
Presenting Data in DataFrames
Pandas provides a very easy mechanism for plotting your data via .plot() function
Data handling & analysis with Pandas
Presenting Data in DataFrames
Plotting data with Matplotlib $ pip install matplotlib.
1. Parts of a Figure
A figure consists of the following elements :
- Title of the figure. - Axes, together with their ticks, tick labels,
and axis labels. - The canvas of plot, which consists of a
drawing of your data in the form of a dots (scatter plot), lines
(line plot), bars (bar plot), surfaces etc. - Legend, which informs
the perceiver about the different plots in the canvas.
Data handling & analysis with Pandas
Preparing your Data for Plotting
Matplotlib expects numpy arrays as input and therefore, if you have your data in a numpy array, you can directly plot it
without any data type conversion. With pandas DataFrame, the behavior is not guaranteed and therefore, it is recommended
that the values in a DataFrame are first converted to a numpy array
Data handling & analysis with Pandas
Drawing Single Plots There are two ways to plot with matplotlib: In an object oriented style or Pyplot style
Data handling & analysis with Pandas
Drawing Single Plots There are two ways to plot with matplotlib: In an object oriented style or the so-called Pyplot style
Data handling & analysis with Pandas
Drawing Multiple Plots in a Figure
Thank You