Postingan

Menampilkan postingan dengan label Python

Convert Epoch Time to Datetime in Python

import datetime epoch_time =  1541290680 result_datetime = datetime.datetime.fromtimestamp(epoch_time) print(result_datetime)  # prints 2018-11-04 12:18:00 or alternatively, if you're in rush, head to online epoch converter here code source:  https://www.javatpoint.com/python-epoch-to-datetime

Word Wrapping in Google Colab using textwrap

  import textwrap wrapper = textwrap.TextWrapper(width=40, initial_indent=" " * 4, subsequent_indent=" " * 4, break_long_words=False, break_on_hyphens=False) print( wrapper.fill (string)) source

Using dict.get()

dict.get()  is used to get the value of an item in a given dictionary using its key (see W3Schools for further reference). Why do we use e this method? We can access the item value just by calling its key directly, can't we? (e.g. dict[key]) I think the main advantage of this method is we can actually check whether or not a key exists in the given dictionary without having the hassle of getting an error returned if the key does not exist. How come? dict.get()  accepts two parameters: the key itself and ... the value   (optional).  The value  will return a specified value if the key we look for does not exist in the dictionary. Example: Suppose we have a dictionary, namely d, as follows: d = {'a': 1, 'b':2, 'c':3} Suppose we would like to get the value of an item with key = 'z'.  d['z'] will raise an error due to the fact that there is no item in the dictionary d whose key is 'z'.  Now, if we apply dict.get() as follows:  dict.get(...

How to Get The Replication Factor of HDFS Files

Gambar
 There are two ways to get the replication factor of HDFS files.  Suppose we want to obtain the replication factor of the 2016 Olympic's Tweet dataset stored in  /data/olympictweets2016rio.  The first way would be to run the following command from your terminal: which will be returning the replication factor as follows: As shown above, the replication factor is 10. However, in most cases, the default replication factor is 3. The other way would be simply using hadoop fs -ls command. Just make sure you state the path of the dataset from which you want to obtain the replication factor. The above command will be returning the information of the target directory or files. Have a look at the replication factor represented by the second column right after the permission part. Both ways return the exact replication factor, which in this case is 10. reference: StackOverflow

Training a Classifier

Gambar
As I write this post, I have been waiting for the training process to be completed. It's still the first epoch but it feels like it is taking ages. Forgive me, by the time I uploaded this image, it has reached the 4th epoch.  The first epoch is yet to be concluded. The accuracy is somehow far from my expectation. Anyway, it's still on the first epoch, so things might be about to change. At this stage, I am surprised by how much a love-hate relationship is involved in training a classifier. You get excited when your result meets your expected threshold but most of the time, you are left disappointed.  But still, I cannot find any other things quite interesting to do. I love how data can transform into valuable insight. I love how to spot patterns out of so-called trash and raw data. But really, I am just too lazy to explore further and anticipate more options of workaround to improve the classifier's performance. Not to mention how intimidated I am to see the progress made b...

How to Print Today's Date and Current Timestamp in Python

Gambar
 

Punctuation Removal using Python

Gambar
Let a string variable named s  = '!!ab#c???' Use the following lines to remove all punctuations from s The result of the code above: Clean and concise! London, January 26 2022