PYTHON PROGRAMMING: 3 BOOKS IN 1 Learn machine learning, data science and analysis with a crash course for beginners. Included coding exercises for artificial intelligence, Numpy, Pandas and Ipython. by Test Jason

PYTHON PROGRAMMING: 3 BOOKS IN 1 Learn machine learning, data science and analysis with a crash course for beginners. Included coding exercises for artificial intelligence, Numpy, Pandas and Ipython. by Test Jason

Author:Test, Jason [Test, Jason]
Language: eng
Format: epub
Published: 2020-08-01T16:00:00+00:00


In exercise, we mostly use positive indexing to obtain elements of the list. Negative indexing is helpful whenever we want to pick the last element in such a list, mostly if the list is lengthy, and by calculating, we cannot figure out the length.

Note that when we use an index number just outside of the scope of the two indexing schemes, we are going to have an IndexError.

How about using negative indexing to remove from each of the top 3 rows the user rating (the very last value) and afterwards average it.

row_1 [-1]=rating_1

row_2[-1]=rating_2

row_3[-1]=rating_3

rating_1 + rating_2 + rating_3=total_rating

total_rating / 3= average_rating

print(average)

2422346.33333

Slice Python Lists

Rather than selecting the list elements separately, we can pick two consecutive elements using a syntax shortcut:

While selecting the first n elements from a list called a list (n stands for a number), we can use the list syntax shortcut [0: n]. In the above example, we had to choose from the list row 3 the first three elements, so we will use row 3[0:3].

When the first three items were chosen, we sliced a portion of the set. For this function, the collection method for a section of a list is known as list slicing.

List slice can be done in many ways:

Retrieving any list slice we need:

Firstly identify the first and last elements of the slice.



Download



Copyright Disclaimer:
This site does not store any files on its server. We only index and link to content provided by other sites. Please contact the content providers to delete copyright contents if any and email us, we'll remove relevant links or contents immediately.