1.Write a function which takes a string that contains
two words separated by any amount of whitespace, and returns a
string in which the words are swapped around and the whitespace is
preserved. Hint: use regular expressions where \s detects the
whitespaces in a string.
Example: given "Hello World",
return
"World Hello"
2.Pandas exercises:
Write a python program using Pandas to create and
display a one-dimensional array-like object containing an array of
data.
Write a python program using Pandas to convert a Panda
module Series to Python list and print it's type. (Hint: use
ds.tolist() to convert the pandas series ds to a list)
Create a pandas dataframe called my_df with
index as integer numbers between 0 to 10, first column (titled
"rnd_int") as 10 integer random numbers between 10-25, second
column ("rnd_float") as 10 random continuous numbers (not
necessarily integer) between 15-40, and third column
("rnd_strBool") as 10 random string values that are either "True"
or "False" (Hint: numpy.random.uniform(a,b,count) and
numpy.random.randint(a,b,size=count) can be helpful)
1.
def swap(line): # Function that will swap words of string
# splitting the string into words
words = line.split(' ')
# then reverse the splitted words and attach the whitespace
swapped_words = ' '.join(reversed(words))
#return the new swapped string
return swapped_words
input = 'Hello world'
print (swap(input) )
Get Answers For Free
Most questions answered within 1 hours.