CSC 552.201 - Advanced Unix Programming, Fall, 2008

CSC 552.201 - Advanced Unix Programming, Fall, 2008

CSC 458 Predictive Analytics I, Fall 2018, Intro. To Python This is an outline. Come to class or attend via RTVC and play along as we play with Python to learn how it works. Introduction to Python ~parson/DataMine/prepdata1 has two examples. is my completed, working code example. is my solution to last falls assignment 1.

Both of these Python programs extract data from a raw data text file and format it for an ARFF file (Attribute Relation File Format) for use by the Weka data mining tool. In ~parson/DataMine see lsTOarff.rawtestdata.txt lsTOarff.arff.ref psTOarff.rawtestdata.txt psTOarff.arff.ref. Pythons read-eval-print UI. You can interact with Python to compute interactively. It can also interpret script files.

You create variables on the fly. They hold whatever type of data you put into them. $ python V # Can be version 2.x or 3.x. Use 2.x per course page. Python 2.7.5 $ python >>> a = 2 ; b = 4.7 ; (a - 7) * b -23.5 # ; and newline are command separators Python uses indentation, not {}, to delimit flow-of-control constructs

>>> a = 7 >>> if a <= 7: print (a, "Is low) else: print(a, "is high) 7 Is low # Do NOT mix leading spaces with TABS in assignments. # Use leading spaces to be compatible with handouts. for loop iterates over list of values. >>> a = 7

>>> mylist = [a, 'a', "Strings use either delimiter"] >>> for s in mylist: print(s) 7 a Strings use either delimiter range() creates a list of numbers >>> for i in range(1,3): print("i is", i) # Note that the final value is exclusive i is 1

i is 2 >>> for i in range(3,-3,-2): # -2 here is an increment print("i is", i) i is 3 i is 1 i is -1 Use and, or, not instead of &&, ||, ! as used in Java or C++ >>> a = 1 ; b = 5 >>> while (a <= 3) and (b >= 3):

print("a, b", a, b) a += 1 ; b = b - 2 a, b 1 5 a, b 2 3 >>> print("a, b", a, b) a, b 3 1 Basic data types Basic data types include strings, ints, floats, and None, which is Pythons no value type. Use a raw string to make escape sequences literal.

>>> a = "a string" ; b = 'another string' ; c = -45 ; d = 4.5 ; e = None >>> print(a,b,c,d,e) a string another string -45 4.5 None >>> raws = r'a\n\nraw string' >>> print(raws) a\n\nraw string Aggregate data types A Python list is a sequence of values. A dictionary maps keys to values.

We wont use sets or tuples in assignment 1. >>> L = ['a', 1, ["b", 2]] >>> for e in L: print(e) a 1 ['b', 2] Dictionary maps keys to values >>> m = {'a': 1, "b" : 2} ; m['c'] = 3 >>> for k in m.keys():

print(k, m[k]) a1 c3 b2 >>> 'b' in m # same as 'b' in m.keys() # Python 2.x allows: m.has_key('b') True >>> 'z' in m False Python has functions and classes

We will not use them in assignment 1. >>> def f(a, b): ... return a + b ... >>> f(1, 3.5) 4.5 >>> f("prefix", 'suffix') 'prefixsuffix' Library modules & more We will go over the re (regular expression),

sys (system), and datetime modules functions used in assignment 1 when we go over it. Come to class. We will explore Python in class in person or via RTVC. has a tutorial and more detailed documentation.

Recently Viewed Presentations

  • PGDTF Planning - Electric Reliability Council of Texas

    PGDTF Planning - Electric Reliability Council of Texas

    PGDTF Introduction. On October 30, 2014, ROS approved the scope for the Planning Geomagnetic Disturbance Task Force (PGDTF) Since that time, the Task Force has met monthly to discuss the ERCOT system's approach to compliance with TPL-007-1.
  • What do you know already? Nutrients  What are

    What do you know already? Nutrients What are

    If a protein food contains a lot of the indispensible amino acids it is said to have a high biological value (HBV), if it is low in any of the indispensable amino acids, it is said to have a low...
  • Click to add title -

    Click to add title -

    The Egyptian Automatic Clearing House (EG-ACH) is a nationwide Electronic Funds Transfer (EFT) network. EG-ACH processes batches of interbank Credit and Debit transactions. EG-ACH facilitates a wide range of Customer to Customer (C2C) payments such as salary distribution, supplier payment,...
  • Sandy Bridge NDA GOLD pre-sales presentation rev 2.0

    Sandy Bridge NDA GOLD pre-sales presentation rev 2.0

    The performance and technology advancements in the Intel Xeon processor E5 family can help us future proof our data center investment with technology we can build on as we evolve new service models to support the business. With the Intel...
  • OBJECTIVES - Loudoun County Public Schools

    OBJECTIVES - Loudoun County Public Schools

    We will apply health knowledge and skills to the development and analysis of personal goals to achieve and maintain long-term health and wellness. I will be able to demonstrate the 6 steps to applying a sling. I will be able...
  • Unit #4: Periodic Table

    Unit #4: Periodic Table

    H.G.J. Moseley (1913)- English a. developed idea of atomic number b. used x-rays to determine the atomic number of elements c. corrected Mendeleev's table by arranging elements according to atomic number, not atomic mass d. founded modern periodic law: when...
  • Review: What is Cultural Diffusion? - Geography

    Review: What is Cultural Diffusion? - Geography

    Define Cultural Imperialism. The practice of promoting the culture, values or language of one nation in another. It is usually the case that the former is a large, economically or militarily powerful nation and the latter is a smaller, less...
  • Chapter 4: Network Access Instructor Materials CCNA Routing

    Chapter 4: Network Access Instructor Materials CCNA Routing - Lab - Building an Ethernet Crossover Cable. Fiber Optic CablingProperties of Fiber Optic Cabling. Transmits data over longer distances and at higher bandwidths. Transmit signals with less attenuation and is completely immune to EMI and RFI.