Thursday, 29 October 2020

Jenkins __pycache__/__init__.cpython-37.pyc: Operation not permitted

 sudo chown -R jenkins:jenkins /var/lib/jenkins/workspace


from : https://stackoverflow.com/questions/50782740/why-is-jenkins-suddenly-unable-to-delete-a-workspace

Thursday, 22 October 2020

Tuesday, 20 October 2020

How do I copy a string to the clipboard using Python?

 The simplest way is with pyperclip. Works in python 2 and 3.

To install this library, use:

pip install pyperclip

Example usage:

import pyperclip

pyperclip.copy("your string")

If you want to get the contents of the clipboard:

clipboard_content = pyperclip.paste()


from : 

https://stackoverflow.com/questions/579687/how-do-i-copy-a-string-to-the-clipboard-on-windows-using-python

https://stackoverflow.com/questions/45014501/trying-to-write-copied-data-in-a-text-file-in-python

start index at 1 for Pandas DataFrame

 Index is an object, and default index starts from 0:

>>> result.index
Int64Index([0, 1, 2], dtype=int64)

You can shift this index by 1 with

>>> result.index += 1 
>>> result.index
Int64Index([1, 2, 3], dtype=int64)


from : https://stackoverflow.com/questions/20167930/start-index-at-1-for-pandas-dataframe

Pandas is treating integer values as strings while sorting? why?

 convert the values to integer:

df['contig'] = df['contig'].astype(int)
df['pos'] = df['pos'].astype(int)

Then sort with inplace

df.sort_values(by=['contig', 'pos'], inplace=True, ascending=True)


from : https://stackoverflow.com/questions/43396993/pandas-is-treating-integer-values-as-strings-while-sorting-why/43400971

AttributeError: Can only use .str accessor with string values, which use np.object_ dtype in pandas

 As the error states, you can only use .str with string columns, and you have a float64. There won't be any commas in a float, so what you have won't really do anything, but in general, you could cast it first:

dc_listings['price'].astype(str).str.replace...


from : https://stackoverflow.com/questions/52065909/attributeerror-can-only-use-str-accessor-with-string-values-which-use-np-obje

How to calculate a Pandas DataFrame time difference between two columns in Python

 datetime objects can be placed in Pandas DataFrame columns. Two columns can be subtracted to return a series of timedelta objects representing the time difference between each row in the two columns.

USE pandas.to_datetime() TO CALCULATE A PANDAS DATAFRAME TIME DIFFERENCE BETWEEN TWO COLUMNS

Call pandas.to_datetime(column) with column as a column of time strings to return a Pandas Series of datetime objects. Use the syntax df.second - df.first to subtract the first column from the second column.

df = pd.DataFrame(columns=["one", "two"])


df.one = ["2019-01-24","2019-01-27"]
df.one = pd.to_datetime(df.one)

df.two = ["2019-01-28", "2020-01-29"]
df.two = pd.to_datetime(df.two)

print(df)
OUTPUT
         one        two
0 2019-01-24 2019-01-28
1 2019-01-27 2020-01-29

difference = (df.two - df.one)

print(difference)
OUTPUT
0     4 days
1   367 days
dtype: timedelta64[ns]


from : https://www.kite.com/python/answers/how-to-calculate-a-pandas-dataframe-time-difference-between-two-columns-in-python

Friday, 16 October 2020

How to read a file into a variable in shell?

#!/bin/sh
value=`cat config.txt`
echo "$value"


from :  https://stackoverflow.com/questions/7427262/how-to-read-a-file-into-a-variable-in-shell

How to set current working directory to the directory of the script in bash?

#!/bin/bash
cd "$(dirname "$0")"


from :  https://stackoverflow.com/questions/3349105/how-to-set-current-working-directory-to-the-directory-of-the-script-in-bash

How to replace multiple patterns at once with sed?

Maybe something like this:

sed 's/ab/~~/g; s/bc/ab/g; s/~~/bc/g' 


from : https://stackoverflow.com/questions/26568952/how-to-replace-multiple-patterns-at-once-with-sed

How to check if a file contains a specific string using Bash

 In case if you want to check whether file does not contain a specific string, you can do it as follows. if ! grep -q SomeString "$File...