You are on page 1of 7

1. Python use of matplotlib package in python.

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.

Exploratory Data Analysis (EDA):

Before diving into complex data analysis, EDA involves visualizing data to gain
insights and understand its characteristics.

Statistical Analysis and Reporting:

Matplotlib is used in scientific research, data analysis, and reporting to visualize


statistical findings, experimental results, and model outputs.

Time Series Analysis and Forecasting:

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

3. Write syntax of method to sort a list

List.sort()

4. Give membership operator in python

in Operator:

The in operator checks if an element exists in a sequence. It returns True if the


element is present, and False otherwise

my_list = [1, 2, 3, 4, 5]
if 3 in my_list:

print("3 is present in the 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.

my_string = "Hello, world!"

if 'x' not in my_string:

print("'x' is not present in the string.")

5. Explain with example identation , variable

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:

print("This line is inside the if block.")

if nested_condition:

print("This line is inside the nested if block.")

print("This line is outside the if block.")

6. Write wht is numpy , pandas

Numpy:

Numerical Python (NumPy):

NumPy is a fundamental Python library for numerical and scientific computing. It


provides support for arrays, matrices, mathematical functions, random number
generation, linear algebra, and more.
Arrays and Data Structures:

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:

NumPy supports multi-dimensional arrays, including 1-dimensional arrays (vectors),


2-dimensional arrays (matrices), and n-dimensional arrays (tensors).

Pandas:

Data Manipulation and Analysis Library:

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.

DataFrame and Series:

The core data structures in pandas are the DataFrame and Series.

DataFrame: A DataFrame is a 2-dimensional labeled data structure with columns of


potentially different data types. It resembles a spreadsheet or SQL table and is
suitable for analyzing structured data.

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.

Indexing and Selection:

Pandas allows for flexible indexing and selection of data elements within a
DataFrame or Series.

7. Difference between list & tuple

Aspect Lists Tuples


Mutability Mutable Immutable
Syntax Defined with [] Defined with () (optional)
Usage Variable-length, modifiable collections Fixed-length, constant collections
Aspect Lists Tuples
Performance Slower due to mutability Faster and more memory-efficient
Function Return Often used for modifiable results Used for constant results

8. Explain open() and write()

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.

'r': Read mode (default), opens a file for reading.

'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.

'b': Binary mode, for handling binary files.

't': Text mode (default), for handling text files.

file = open('example.txt', 'w')

file.write("Hello, this is some text written to the file.\n")

file.write("This is another line of text.\n")

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 = open('example.txt', 'a')

file.write("This is additional text appended to the file.\n")

file.write("Appending more data.\n")

file.close()
9. write a program to create class student with roll no & display its content

class Student:

def __init__(self, roll_no):

self.roll_no = roll_no # Initialize roll number attribute

def display_details(self):

print("Student Roll Number:", self.roll_no)

# Create an instance of the Student class

student1 = Student(101)

# Display the student's details

student1.display_details()

10. Wap to generate 5 random integer between 10 , 50 using numpy.

import numpy as np

random_numbers = np.random.randint(10, 51, size=5)

print(random_numbers)

11. What us multiple inheritance give example.

Definition: Multiple inheritance is a feature in some object-oriented programming


languages where a class can inherit behavior and attributes from more than one parent class.

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):

print("Method from Base1")

class Base2:
def method_base2(self):

print("Method from Base2")

class Derived(Base1, Base2):

def method_derived(self):

print("Method from Derived")

# Create an object of the Derived class

obj = Derived()

# Call methods from Derived class

obj.method_derived()

# Call methods from Base1 class

obj.method_base1()

# Call methods from Base2 class

obj.method_base2()

12. Various file objects ()

Read Mode ('r'):

This mode is used for reading from a file.

If the file does not exist or cannot be opened for reading, it raises a FileNotFoundError.

The file pointer is placed at the beginning of the file.

Write Mode ('w'):

This mode is used for writing to a file.

If the file exists, its contents are truncated. If the file does not exist, a new file is created.

The file pointer is placed at the beginning of the file.


Append Mode ('a'):

This mode is used for appending data to the end of a file.

If the file does not exist, it creates a new file.

The file pointer is placed at the end of the file.

Read and Write Mode ('r+'):

This mode is used for both reading from and writing to a file.

The file pointer is placed at the beginning of the file.

Write and Read Mode ('w+'):

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.

The file pointer is placed at the beginning of the file.

Append and Read Mode ('a+'):

This mode is used for both reading from and appending to a file.

If the file does not exist, it creates a new file.

The file pointer is placed at the end of the file.

Binary Mode ('b'):

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.

You might also like