Python PPR
Python PPR
Data Visualization:
Matplotlib is widely used for creating various types of visualizations to represent data
effectively. This includes line plots, scatter plots, bar charts, histograms, pie charts,
box plots, heatmaps, and more.
Before diving into complex data analysis, EDA involves visualizing data to gain
insights and understand its characteristics.
Time series data, such as stock prices, weather data, and sensor readings, are
visualized using Matplotlib to analyze trends, seasonality, and anomalies.
2. 4 data structures
List
Tuple
Dictionary
Set
List.sort()
in Operator:
my_list = [1, 2, 3, 4, 5]
if 3 in my_list:
not in Operator:
The not in operator checks if an element does not exist in a sequence. It returns True
if the element is not present, and False otherwise.
Indentation in Python refers to the spaces or tabs placed at the beginning of a line of
code to indicate its level of nesting within a block of code. Indentation is crucial in
Python because it defines the structure and hierarchy of code blocks, such as in
control structures (if statements, loops, etc.) and function definitions.
Unlike some other programming languages that use curly braces {} or keywords like
begin and end to denote code blocks, Python uses indentation for readability and
clarity.
if condition:
if nested_condition:
Numpy:
NumPy's main object is the ndarray, which stands for n-dimensional array. This data
structure allows you to create and manipulate arrays of homogeneous (same data
type) or heterogeneous (mixed data type) elements.
Multi-dimensional Arrays:
Pandas:
Pandas is a powerful Python library designed for data manipulation and analysis. It
provides easy-to-use data structures and functions for handling structured data, such
as tabular data, time series, and other labeled data formats.
The core data structures in pandas are the DataFrame and Series.
Series: A Series is a 1-dimensional labeled array capable of holding any data type. It
represents a single column or row in a DataFrame.
Pandas allows for flexible indexing and selection of data elements within a
DataFrame or Series.
open() Function:
The open() function is used to open a file in Python. It takes two arguments: the file
name (or file path) and the mode in which the file should be opened. The mode
specifies whether the file should be opened for reading, writing, appending, etc.
'w': Write mode, opens a file for writing. If the file already exists, it will be overwritten.
If the file does not exist, a new file will be created.
'a': Append mode, opens a file for appending. New data will be added to the end of the
file.
file.close()
write() Method:
The write() method is used to write data to a file that has been opened in write ('w') or
append ('a') mode. It takes a string as an argument and writes the string to the file.
Each call to write() appends the data to the file at the current file position.
file.close()
9. write a program to create class student with roll no & display its content
class Student:
def display_details(self):
student1 = Student(101)
student1.display_details()
import numpy as np
print(random_numbers)
Usage in Python: In Python, a class can inherit from multiple base classes, allowing it to
inherit attributes and methods from each of them.
Example :
class Base1:
def method_base1(self):
class Base2:
def method_base2(self):
def method_derived(self):
obj = Derived()
obj.method_derived()
obj.method_base1()
obj.method_base2()
If the file does not exist or cannot be opened for reading, it raises a FileNotFoundError.
If the file exists, its contents are truncated. If the file does not exist, a new file is created.
This mode is used for both reading from and writing to a file.
This mode is used for both reading from and writing to a file.
If the file exists, its contents are truncated. If the file does not exist, a new file is created.
This mode is used for both reading from and appending to a file.
This mode is used in conjunction with the above modes to indicate that the file should be
treated as a binary file.
It is often used when working with non-text files, such as images or executables.
For example, 'rb' indicates reading a binary file, 'wb' indicates writing to a binary file, and so
on.