Notes
Notes - notes.io |
- Data type in python ?
- What is an exception. Conversion with exception try catch
def convertInt(instring):
try :
return int(instring)
except:
return -1
- define a class with an attribute name, age and a method change_name to change its name
class Dog:
def __init__(self, name, age):
self.name = name
self.age = age
def change_name(self, new_name):
self.name = new_name
Define a Dog object named "Oscar"
Change the name of this Dog to "Enzo"
-What is regex. What does this regex do ?
>>> df = pd.DataFrame([[4, 9]] * 3, columns=['A', 'B'])
>>> df
A B
0 4 9
1 4 9
2 4 9
#try math to see if work
>>> df.apply(np.sqrt)
A B
0 2.0 3.0
1 2.0 3.0
2 2.0 3.0
>>> df.apply(np.sum, axis=0)
A 12
B 27
dtype: int64
>>> df.apply(np.sum, axis=1)
0 13
1 13
2 13
dtype: int64
>>> df.apply(lambda x: [1, 2], axis=1)
0 [1, 2]
1 [1, 2]
2 [1, 2]
-Data frame : df with columns : ID, FirstName, LastName, NumberOfTransactions, AccountBalance, PhoneNumber, PostalCode, Email, Address
a. Convert Last Name to upper df["LastName"]=df["LastName"].upper()
b. Create FullName column with FirstName concatenated with LastName seperated by a space df["FullName"]=df["FirstName"]+' '+df["LastName"]
c. Use function ConvertInt above to clean the NumberOfAccounts columns. Column may contain values such as 1.0; 2,0; "NA"
d. Order customer by decreasing order of NumberOfTransactions, stored in df_sort
e. From the result of df_sort, select the top 5 customers with the highest number of transaction, create a simple report : "Top 5 customers with highest number of transactions are John SMITH, Mary CLAIR, Henry FORD, Bill SUMMER, Nicholas TESLA". Please consider a method that does not involve manually appending one customer after another, as it will not be scalable to respond to the question "top 1000 customers" instead of "top 5" df["FullName"].tolist() or list(df["FullName"]) then ','.join()
f.regex extract phone region from number (437) 226
g. Convert "20191130" to format "2019-11-30"
h. join
i. summary partition window function
-Dataframe Join
-What is Spark UDF, Spark dataframe, lazy evaluation ?
|
Notes.io is a web-based application for taking notes. You can take your notes and share with others people. If you like taking long notes, notes.io is designed for you. To date, over 8,000,000,000 notes created and continuing...
With notes.io;
- * You can take a note from anywhere and any device with internet connection.
- * You can share the notes in social platforms (YouTube, Facebook, Twitter, instagram etc.).
- * You can quickly share your contents without website, blog and e-mail.
- * You don't need to create any Account to share a note. As you wish you can use quick, easy and best shortened notes with sms, websites, e-mail, or messaging services (WhatsApp, iMessage, Telegram, Signal).
- * Notes.io has fabulous infrastructure design for a short link and allows you to share the note as an easy and understandable link.
Fast: Notes.io is built for speed and performance. You can take a notes quickly and browse your archive.
Easy: Notes.io doesn’t require installation. Just write and share note!
Short: Notes.io’s url just 8 character. You’ll get shorten link of your note when you want to share. (Ex: notes.io/q )
Free: Notes.io works for 12 years and has been free since the day it was started.
You immediately create your first note and start sharing with the ones you wish. If you want to contact us, you can use the following communication channels;
Email: [email protected]
Twitter: http://twitter.com/notesio
Instagram: http://instagram.com/notes.io
Facebook: http://facebook.com/notesio
Regards;
Notes.io Team