0% found this document useful (0 votes)
4 views

DS Python

Uploaded by

paxobe3782
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
4 views

DS Python

Uploaded by

paxobe3782
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 7

Data Science(3151608) Practical-1 220760116028

Sr No Name of the Experiment CO Date


1 A) Hence on session on jupyter notebook and explore
anaconda.
B) Basic operation on python data structure String, Set,
Tuple, Dictionary.

What is Python?

Python is a popular programming language. It was created by Guido van Rossum, and released
in 1991.

It is used for:

• web development (server-side),


• software development,
• mathematics,
• system scripting.

Basic Operation on Python Data Structure that is String, List,


Tuple, Set, Dictionary.

String:
Strings in python are surrounded by either single quotation marks, or double quotation marks.

'hello' is the same as "hello".

You can display a string literal with the print () function:

print("Hello")

print('Hello')

a = "Hello"
print(a)

Gujarat Technological University pg. 1


Data Science(3151608) Practical-1 220760116028

Check String: txt = "The best things in life are free!"


print("free" in txt)

Slicing: b = "Hello, World!"


print(b[2:5])

String Methods:
find (): Searches the string for a specified value and returns the position of where it was found
index (): Searches the string for a specified value and returns the position of where it was found
lower (): Converts a string into lower case
split (): Splits the string at the specified separator, and returns a list

List:
Lists are used to store multiple items in a single variable.

List is a collection which is ordered and changeable. Allows duplicate members.

thislist = ["apple", "banana", "cherry"] print(thislist)

mylist = ["apple", "banana", "cherry"] print(type(mylist))

Gujarat Technological University pg. 2


Data Science(3151608) Practical-1 220760116028

String, int and boolean data types:


list1 = ["apple", "banana", "cherry"]
list2 = [1, 5, 7, 9, 3]
list3 = [True, False, False]

It is also possible to use the list () constructor when creating a new list.

thislist = list (("apple", "banana", "cherry"))


print(thislist)

List items are indexed and you can access them by referring to the index number:

thislist = ["apple", "banana", "cherry"] print(thislist[1])

To change the value of a specific item, refer to the index number:

thislist = ["apple", "banana", "cherry"]


thislist[1] = "blackcurrant"
print(thislist)

To add an item to the end of the list, use the append () method:

thislist = ["apple", "banana", "cherry"]


thislist.append("orange")
print(thislist)

Gujarat Technological University pg. 3


Data Science(3151608) Practical-1 220760116028

To insert a list item at a specified index, use the insert () method.


thislist = ["apple", "banana", "cherry"]
thislist.insert(1, "orange")
print(thislist)

Set:
Sets are used to store multiple items in a single variable.

Set items are unordered, unchangeable, and do not allow duplicate values.

thisset = {"apple", "banana", "cherry"}


print(thisset)

thisset.remove("banana")

thisset.add("orange")

Set Methods:
add () Adds an element to the set
clear () Removes all the elements from the set
copy () Returns a copy of the set

Gujarat Technological University pg. 4


Data Science(3151608) Practical-1 220760116028

Tuples:
Tuples are used to store multiple items in a single variable.

Tuple items are ordered, unchangeable, and allow duplicate values.

thistuple = ("apple", "banana", "cherry", "apple", "cherry")


print(thistuple)

Once a tuple is created, you cannot change its values. Tuples are unchangeable,
or immutable as it also is called.

But there is a workaround. You can convert the tuple into a list, change the list, and convert the
list back into a tuple.

x = ("apple", "banana", "cherry")


y = list(x)
y[1] = "kiwi"
x = tuple(y)
print(x)

Dictionary:
Dictionaries are used to store data values in key:value pairs.

Dictionary items are ordered, changeable, and do not allow duplicates.

thisdict = {
"brand": "Ford",
"model": "Mustang",
"year": 1964
}
print(thisdict)

Gujarat Technological University pg. 5


Data Science(3151608) Practical-1 220760116028

Adding an item to the dictionary is done by using a new index key and assigning a value to
it:

thisdict = {
"brand": "Ford",
"model": "Mustang",
"year": 1964
}
thisdict["color"] = "red"
print(thisdict)

Explore Anaconda
Anaconda is a popular distribution of the Python and R programming languages for data science,
machine learning, and scientific computing. It simplifies package management and deployment
by providing a comprehensive ecosystem of tools and libraries pre-installed. Here are some key
aspects and features of Anaconda:
1. Package Management: Anaconda includes the Conda package manager, which allows
you to easily install, update, and manage packages and dependencies. Conda can install
packages from the Anaconda repository as well as from other repositories such as PyPI
(Python Package Index).
2. Cross-Platform: Anaconda supports Windows, macOS, and Linux platforms, making
it versatile for development and deployment across different operating systems.
3. Integrated Development Environment (IDE): Anaconda comes with Spyder, an
opensource IDE designed specifically for scientific computing and data analysis. It also
integrates well with other popular IDEs such as Jupyter Notebook and JupyterLab.
4. Wide Range of Packages: Anaconda includes a vast collection of pre-installed
libraries and tools commonly used in data science and scientific computing, such as
NumPy, Pandas, Matplotlib, SciPy, Scikit-learn, and many others. This reduces the setup
time and ensures compatibility among the packages.
5. Virtual Environments: Conda allows you to create isolated environments that can
have their own Python version and set of installed packages. This helps in managing
dependencies and avoiding conflicts between different projects.

Gujarat Technological University pg. 6


Data Science(3151608) Practical-1 220760116028

6. Conda Channels: Besides the default Anaconda repository, there are


communitymaintained channels where you can find additional packages not available in
the default repository.
7. Data Visualization: Anaconda includes tools for data visualization such as Matplotlib,
Plotly, and Seaborn, which are essential for creating insightful visual representations of
data.
8. Education and Training: Anaconda provides resources for learning and training in
data science and machine learning through its documentation, tutorials, and community
support.

Overall, Anaconda is widely used by data scientists, researchers, and developers due to its ease
of use, extensive package support, and robust ecosystem tailored for scientific computing and
data analysis workflows.

Gujarat Technological University pg. 7

You might also like