Please note, this is a STATIC archive of website www.tutorialspoint.com from 11 May 2019, cach3.com does not collect or store any user information, there is no "phishing" involved.
Tutorialspoint

Working with Text Data

import pandas as pd
import numpy as np

s = pd.Series(['Tom', 'William Rick', 'John', 'Alber@t', np.nan, '1234','SteveSmith'])

print s
print "                                       "
print s.str.lower()
print "                                       "
print s.str.upper()
print "                                       "
print s.str.len()
print "                                       "
print "Adding String "
print s.str.cat(sep='_')



print "                                       "
print "                                       "
print "Contains match "

s = pd.Series(['Tom ', ' William Rick', 'John', 'Alber@t'])
print s.str.contains(' ')

print "Replace "
print "                                       "
print "                                       "


print s.str.replace('@','$')


s = pd.Series(['Tom ', ' William Rick', 'John', 'Alber@t'])

print "                                       "
print "                                       "
print ("The number of 'm's in each string:")
print s.str.count('R')
print s.str.contains('r')
print "                                       "
print "                                       "
print ("Starts with:")
print s.str.startswith('J')
print ("Starts with:")
print s.str.endswith('t')


s = pd.Series(['Tom ', ' William Rick', 'John', 'Alber@t'])

print s.str.find('e')

# "-1" indicates that there no such pattern available in the element.


s = pd.Series(['Tom ', ' William Rick', 'John', 'Alber@t'])

print s.str.findall('e')


#Null list([ ]) indicates that there is no such pattern available in the element.

s = pd.Series(['Tom', 'William Rick', 'John', 'Alber@t'])
print s.str.swapcase()


print s.str.islower()
# to validate full string in lower 

print s.str.isupper()
# to validate full string in upper

print s.str.isnumeric()
# to validate full string in Numeric 

euler

# Hello World program in Python
# Euler method in Python - 
from __future__ import division
from math import exp
import matplotlib.pyplot as plt
import numpy as np

h=0.01
x0=0
y0=1
xmax=4
x=x0
y=y0

print "Euler method\n"
puntsEuler=[]
while x<=xmax:
    puntsEuler.append((x,y))
    print x,y
    k1=(-2*x**3+12*x**2-20*x+8.5)
    y = y + h*k1
    x = x + h
#puntsEuler.append((x,y))
print x,y
print puntsEuler


print '===   Euler   ===='
for i in range(len(puntsEuler)):
    print puntsEuler[i][0],' --> ',puntsEuler[i][1]
print
print '============='


# dibuixant els punts i la solucio 

def f(z):
    return -0.5*z**4+4*z**3-10*z**2+8.5*z+1

te, eu = zip(*puntsEuler)
#tr, rk = zip(*puntsRK)

t1 = np.arange(x0, xmax, h/10)

plt.plot(te,eu,'b-',marker='o')
#plt.plot(tr,rk,'g-',marker='*')
plt.plot(t1,f(t1),'r')
plt.show()

MyProj

# Hello World program in Python
    
print "Hello World!\n"

test

# Hello World program in Python
    
print "Hello World!\n"

Execute Python Online

def find_nth(haystack, needle, n):
    start = haystack.find(needle)
    print "Haystack"
    while start >= 0 and n > 1:
        
        start = haystack.find(needle, start+len(needle))
        print "start :"+str(start)
        print "N: " + str(n)
        n -= 1
    return start
   
def parseSQLFn(inSentence):
  
  sentence = inSentence
  numOpen = sentence.count('(');
  print "sentence count"+str(numOpen)
  ctrOpen = 0
  i = 0
  subSentence = sentence
  missingStr = 0
  finSentence = ''
 
  if numOpen == 0:
    finSentence = inSentence
    return finSentence
 
  while i < numOpen*2:
    print 'i'+ str(i)
    varOpen = subSentence.find('(')
    varClose = subSentence.find(')')
    print 'VAR OPEN'+str(varOpen)
    print 'Var Close'+str(varClose)
   
    # Break condition 1: Open paranthesis ends
    if varOpen < 0:
      j = 0
      
      while j < ctrOpen:
        # Get the End of str
        endOfStr = find_nth(subSentence,')',ctrOpen)
        print "EoS "+str(endOfStr)
        endOfStr+= missingStr + i + 1
        print "EoS "+str(endOfStr)
        ctrOpen=0
     
      finSentence = sentence[:endOfStr]
      # print("finSentence = " + finSentence)
      print "Fin String "+finSentence
      return finSentence
     
    if varOpen < varClose:
      subSentence = subSentence[varOpen+1:]
      print "Subsentence " + subSentence
      missingStr = missingStr + varOpen
      print "Missing str "+str(missingStr)
      ctrOpen+=1
     
    elif varOpen > varClose:
      subSentence = subSentence[varClose+1:]
      print "Subsentence " + subSentence
      missingStr = missingStr + varClose
      print "Missing str "+str(missingStr)
      ctrOpen-=1
      
    i=i+1
   
    # break condition 2: All paranthesis closed but have some tail
    if ctrOpen == 0:
      print "IN CtrOpen"
      finSentence = sentence[:missingStr+i]
      print("finSentence = " + finSentence)
      return finSentence

parseSQLFn('''to_char(sd_sdfdfc(ASS(ddnbcjdbsc_snsjdc),jdchuiadcu)))hguyuy''')

Execute Python Online

# Hello World program in Python
    
print "Hello World!\n"

Execute Python Online

import math   # This will import math module

x = 1
y = 0
while True:
    print(x)
    print(math.floor(math.log10(x))+1)
    y=y+(math.floor(math.log10(x))+1)
    print(y)
    x += 1
    if y == 2007:
        break

2007_v1

import math   # This will import math module

x = 1
y = 0
while True:
    print(x)
    print(math.floor(math.log10(x))+1)
    y=y+(math.floor(math.log10(x))+1)
    print(y)
    x += 1
    if y == 2007:
        break

Speed Date Event

class S_D:
    def __init__(self, price, number): 
        self.price= price
        self.number= number
    
    def performance(self):
        if self.number >22:
            print ('Event was a hit!')
        elif 14<= self.number <= 22:
            print ('Event was good')
        else:
            print('Event was a bust :(')

###Creating first instance
Event1= S_D(15,13)
Event1.performance()

    

Praise GOD

# Hello World program in Python
    
print "Hello World!\n"

Advertisements
Loading...

We use cookies to provide and improve our services. By using our site, you consent to our Cookies Policy.