Python - converted PDF

Summary

This document contains information about Python programming, including fundamental data structures like lists. It also covers methods for working with strings and introduces some related concepts, such as object-oriented programming and data manipulation.

Full Transcript

‫ا‪7‬جموعات هي هياكل بيانات مدمجة تحتوي على‬ ‫‪i‬‬ ‫عناصر بيانات مرتبطة ببعضها البعض‪.‬‬ ‫‪g‬‬ ‫ا‪G‬غاني ا‪7‬فضلة على هاتفك الذكي‪.‬‬ ‫قائمة...

‫ا‪7‬جموعات هي هياكل بيانات مدمجة تحتوي على‬ ‫‪i‬‬ ‫عناصر بيانات مرتبطة ببعضها البعض‪.‬‬ ‫‪g‬‬ ‫ا‪G‬غاني ا‪7‬فضلة على هاتفك الذكي‪.‬‬ ‫قائمة جهات ا‪J‬تصال‪.‬‬ ‫الكتب في مكتبة‪.‬‬ ‫البطاقات في لعبة ورق‪.‬‬ ‫‪J‬عبو الفريق الرياضي ا‪7‬فضل‪.‬‬ ‫ا‪G‬سهم في محفظة استثمارية‪.‬‬ ‫ا‪7‬رضى في دراسة عن السرطان‪.‬‬ ‫قائمة التسوق‪.‬‬ ‫الوصول إلى عناصر القائمة‬ ‫يمكن تعديلها‬ ‫‪see‬‬ O O are soooo sore ‫الحلقة الخارجية ‪ for‬تتكرر على صفوف القائمة‪ ،‬صفًا واحدًا في كل مرة‪.‬‬ ‫‪f‬‬ ‫خ‪E‬ل كل تكرار للحلقة الخارجية ‪ ،for‬تتكرر الحلقة الداخلية ‪for‬‬ ‫على كل عمود في الصف الحالي‪.‬‬ ‫‪E‬‬ ‫ربط‬ ‫‪so‬‬ ‫طريقة سريعة للبحث‬ ‫‪9‬حظ انه اكثر من ‪keys‬‬ ‫يستطيعون ام يمتلكون نفس‬ ‫‪ ،value‬ولكن العكس ‪ 9‬يمكن‬ ‫‪a‬‬ ‫با‪%‬صل هي‬ ‫‪were‬‬ ‫‪soooooo‬‬ ‫إطار البيانات هو هيكل بيانات ثنائي ا‪%‬بعاد‪ ،‬حيث يتم تنظيم البيانات بشكل جدولي في صفوف وأعمدة‪.‬‬ ‫‪a‬‬ ‫‪sent‬‬ ‫‪i‬‬ Road Map Introduction Formatting Strings TOPIC 8- STRINGS Concatenating and Repeating Strings Stripping Whitespace from Strings Changing Character Case Comparison Operators for Strings DR.LIYAKATHUNISA SYED Searching for Substrings Replacing Substrings DEPARTMENT OF COMPUTER SCIENCE Splitting and Joining Strings TAIBAH UNIVERSITY Characters and Character-Testing Methods MADINAH Raw Strings Intro to Data Science: Pandas, Regular Expressions and Data Munging Formatting Strings STRINGS-Applications The table below shows many string processing and NLP-related applications Proper text formatting makes data easier to read and understand Presentation Types Basic string formatting is performed with f-strings. When you specify a placeholder for a value in an f-string, Python assumes the value should be displayed as a string unless you specify another type. In some cases, the type is required. For example, let’s format the float value 17.489 rounded to the hundredths position: Formatting Strings Formatting Strings Formatting Strings Changing Character Case Comparison Operators for Strings Comparison Operators for Strings Strings may be compared with the comparison operators. Recall that strings are compared based on their underlying integer numeric values. So uppercase letters compare as less than lowercase letters because uppercase letters have lower integer values. For example, 'A’ is 65 and 'a' is 97. You’ve seen that you can check character codes with ord: Searching for Substrings Searching for Substrings You can search in a string for one or more adjacent characters—known as a substring—to count the number of occurrences determine whether a string contains a substring, or determine the index at which a substring resides in a string. Each method shown in this section compares characters lexicographically using their underlying numeric values. Searching for Substrings Searching for Substrings Searching for Substrings Searching for Substrings Searching for Substrings Replacing Substrings A common text manipulation is to locate a substring and replace its value. Method replace takes two substrings It searches a string for the substring in its first argument and replaces each occurrence with the substring in its second argument. The method returns a new string containing the results. Let’s replace tab characters with commas: Replacing Substrings Splitting and Joining Strings Joining Strings String method join concatenates the strings in its argument, which must be an iterable containing only string values; otherwise, a TypeError occurs. The separator between the concatenated items is the string on which you call join. The following code creates strings containing comma-separated lists of values: Splitting and Joining Strings Splitting and Joining Strings Splitting Strings String Methods partition and rpartition To tokenize a string at a custom delimiter (such as each comma-and-space String method partition splits a string into a tuple of three strings based pair), specify thedelimiter string (such as, ', ') that split uses to tokenize the on the method’s separator argument. The three strings are string: the part of the original string before the separator, the separator itself, and the part of the string after the separator. This might be useful for splitting more complex strings. Consider a string representing a student’s name and grades: Splitting and Joining Strings Splitting and Joining Strings String Methods partition and rpartition String method partition splits a string into a tuple of three strings based on the method’s separator argument. The three strings are the part of the original string before the separator, the separator itself, and the part of the string after the separator. This might be useful for splitting more complex strings. Consider a string representing a student’s name and grades: 'Amanda: 89, 97, 92' String Method splitlines String Method splitlines Method splitlines returns a list of new strings representing the lines of text split at each newline character in the original string. Recall that Python stores multiline strings with embedded \n characters to represent the line breaks, as shown in snippet : String Method splitlines Characters and Character-Testing Methods Python provides string methods for testing whether a string matches certain characteristics. For example, string method isdigit returns True if the string on which you call the method contains only the digit characters (0–9). You might use this when validating user input that must contain only digits: Characters and Character-Testing Methods Characters and Character-Testing Methods The table below shows many of the character-testing methods. Each method returns False if the condition described is not satisfied: Raw Strings Raw Strings Recall that backslash characters in strings introduce escape sequences—like \n for For such cases, raw strings—preceded by the character r—are more convenient. newline and \t for tab. They treat each backslash as a regular character, rather than the beginning of an escape So, if you wish to include a backslash in a string, you must use two backslash sequence: characters \\. This makes some strings difficult to read. For example, Microsoft Windows uses backslashes to separate folder names when specifying a file’s location. To represent a file’s location on Windows, you might write: Python converts the raw string to a regular string that still uses the two backslash characters in its internal representation, as shown in the last snippet. Raw strings can make your code more readable, particularly when using the regular expressions that we discuss in the next section. Regular expressions often contain many backslash characters. Intro to Data Science: Pandas, Regular Expressions and Raw Strings Data Munging Preparing data for analysis is called data munging or data wrangling. These are synonyms from this point forward, we’ll say data munging. Two of the most important steps in data munging are data cleaning and transforming data into the optimal formats for your database systems and analytics software. Some common data cleaning examples are: deleting observations with missing values, substituting reasonable values for missing values, deleting observations with bad values, substituting reasonable values for bad values, tossing outliers (although sometimes you’ll want to keep them), duplicate elimination (although sometimes duplicates are valid), dealing with inconsistent data, and more. Intro to Data Science: Pandas, Regular Expressions and Intro to Data Science: Pandas, Regular Expressions and Data Munging Data Munging Data Validation Cleaning Your Data Bad data values and missing values can significantly impact data analysis. Some data scientists advise against any attempts to insert “reasonable values.” Instead, they advocate clearly marking missing data and leaving it up to the data analytics package to handle the issue. Let’s consider a hospital that records patients’ temperatures (and probably other vital signs) four times per day. Assume that the data consists of a name and four float values, such as Intro to Data Science: Pandas, Regular Expressions and Intro to Data Science: Pandas, Regular Expressions and Data Munging Data Munging Reformatting Your Data As a simple example, assume that an application requires U.S. phone numbers in the format ###- ###-####,with hyphens separating each group of digits. The phone numbers have been provided to us as 10-digit strings without hyphens. Let’s create the DataFrame: Intro to Data Science: Pandas, Regular Expressions and Data Munging END OF STRINGS ‫مؤقت‬ ‫‪O‬‬ ‫آلية‬ ‫‪0‬‬ o 1 7 output ‫إشارة‬ ‫‪men‬‬ 1 2 soooo

Use Quizgecko on...
Browser
Browser