Saturday, February 23, 2019

Python: Strptime


strptime

String to datetime object = strptime
datetime object to other formats = strftime
Jun 1 2005 1:33PM is equals to %b %d %Y %I:%M%p
%b  - Month as locale’s abbreviated name(Jun)
%d   - Day of the month as a zero-padded decimal number(1)
%Y   - Year with century as a decimal number(2015)
%I   - Hour (12-hour clock) as a zero-padded decimal number(01)
%M  - Minute as a zero-padded decimal number(33)
%p   - Locale’s equivalent of either AM or PM(PM)
 Use slicing to remove unwanted characters if necessary.

Example :
>>> import time
>>> time.strptime('Jun 1 2005  1:33PM', '%b %d %Y %I:%M%p')
time.struct_time(tm_year=2005, tm_mon=6, tm_mday=1,
                 tm_hour=13, tm_min=33, tm_sec=0,
                 tm_wday=2, tm_yday=152, tm_isdst=-1)

Sunday, February 17, 2019

Linux - Format USB Flash Drive

Linux - Format USB Flash Drive


  1. sudo apt-get install gparted
  2. By default it goes to the hard drive of your computer. 
  3. go to the top-right corner of the application and choose the removable media
  4. Before you go for formatting, unmount the disk by right-clicking on the partiti$
  5. right-clicking on it will show you the Format To option. Select FAT32 (Windows Compatible and Audio/Video Compatible).
  6. Edit > Apply all  Operations







Friday, February 15, 2019

Python : Simple CSV reader writer using Pandas

Sample CSV reader /Writer using pandas



import  pandas,os
p="/home/deepak/Python/testData/1.csv"

sheet=pandas.DataFrame( {"rollno":[1,2],"name":["a",'b']})
sheet.to_csv(p)

if(os.path.exists(p)):  
    Obj=pandas.read_csv(p)
    print(Obj.columns) #print all columns
    print(Obj['name'][1]) #Print 1 row 1 col value
    Obj.set_value(0,"name","deepak")
    Obj.to_csv(p)

Python : Change default 2.x version to 3.x in Linux

python : Change default 2.x version to 3.x in Linux



To open python 3x
python3

To install packages
pip3 install <package>




To change default

$python --verion
Python 2.4


# update-alternatives --install /usr/bin/python python /usr/bin/python2.7 1
update-alternatives: using /usr/bin/python2.7 to provide /usr/bin/python (python) in auto mode
 
 # update-alternatives --install /usr/bin/python python /usr/bin/python3.4 2
update-alternatives: using /usr/bin/python3.4 to provide /usr/bin/python (python) in auto mode
 
 
$python --verion
Python3.6

#select versions
update-alternatives --config python

Saturday, February 9, 2019

Version Control: GIT basic Commands in Linux


 GIT basic Commands in Linux


https://rubygarage.org/blog/most-basic-git-commands-with-examples
~~~~~~~~~~Clone Repository~~~~~~~~~~~~~~~
cd Documents
git clone https://github.com/YOUR-USERNAME/YOUR-REPOSITORY
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
~~~~~~~~~~~~~~~~~~give new name to your repository~~~~~~~~~~~~~~
git remote add gitPython https://github.com/j-thepac/Python_snippets.git #set git
cd to git folder
git remote
-------------------------------

~~~~~~~~~~~~~~~~~~~~~~~~Add new file into Git repository~~~~~~~~~~~~~~~

git add file #staging area ready to commit
#git add --all # to add all files to staging area
git status
git commit
#enter the title of the file
git push #push it to current version
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
~~~~~~~~~~~~~Remove files from stagin area~~~~~~~~~~~~~
git rm --cached my-file.ts # remove file from staging area
#git reset
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
git mv [file-original] [file-renamed] # rename file