Python for Data Analysis: The Ultimate Beginner's Guide to Learn The Basics Of Data Analysis, Pandas and Python Statistics. Discover Programming Language and Machine Learning. by Turner Cooper

Python for Data Analysis: The Ultimate Beginner's Guide to Learn The Basics Of Data Analysis, Pandas and Python Statistics. Discover Programming Language and Machine Learning. by Turner Cooper

Author:Turner, Cooper [Turner, Cooper]
Language: eng
Format: epub
Published: 2020-04-15T16:00:00+00:00


Data Structures

Real-world data is usually available in groups or lumps, and it is easier to work with groups since it makes it easier for us to eliminate repetitive code. Numerous data types in Python will make it easier for you to handle large groups of data.

Programmers often use strings, lists, dictionaries, and tuples when they write a script in Python. These data types are known as data structures. Strings are pieces of text that are grouped, while tuples and lists are groups of individual data items that have been grouped. A dictionary is a group of pairs that have the highest considerations. The different methods that are used to access the data in these structures are the same.

You can also look at these data types differently, depending on whether the values that the variable holds can be modified. This is called the mutability of the data type. A string and tuple cannot be modified, but they can be used to create new tuples and strings. A list is mutable, which means that you can either remove or add items to it.

Items in Sequences

You can fetch individual items in a sequence using an index. This index will indicate the position of the element. The index is often an integer that is written in square brackets immediately after the name of the variable. So, you can obtain the variable in a list by specifying the name of the list, followed by the index. You can also access a single character in a string.

>>> vegetable = ‘pumpkin’

>>> vegetable [0]

‘p’

Or an item in a list:

>>>vegetable = [‘pumpkins’, ‘potatoes’, ‘onions’, ‘eggplant’]

>>>vegetable [1]

‘pumpkins’

You will notice that indexing in Python is zero-based. This means that you can only start counting the variables at zero. An index with the number 3 in the square brackets will look at the fourth item in the list since the first item will be indexed as zero. So, you can use any number of integers beginning from zero to index the variables in your data set. A negative index will count the list from the end to the beginning:

>>>vegetable [-1]

‘eggplant’ Slices can be used to grab the different sections in any sequence. This method is used to fetch many items in a sequence. A slice is written using the same notation as an index. The only difference is that a colon separates the integers. The first value is the starting point, and this value is included. The second number in the notation is the endpoint of the slice, and it is exclusive. If you look at s[0:2], the compiler will slice the list from the variable with the index zero and stop exactly before the variable with the index two.

You do not necessarily have to use the third value, and this is an additional step. This can be negative; therefore, you can retrieve all the other items instead of picking this item from the sequential list. Alternatively, you can retrieve items backward as well. So, s [i: j: step] will give you the slice that begins from the variable i, but will not include the variable j.



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.