29 August 2021

Vim auto complete

Type in a few letters, press Ctrl+n (next), or Ctrl+p (previous), a list of candidate words appears, which are all the words in the file, beginning with the a few letters you have typed in.

If the first candidate word is what you want, then you can continue to type in anything you want next.

Otherwise, you can continue to press Ctrl+n, or Ctrl+p, until the candidate word you want, then continue to type in anything you want next.

:help popupmenu-completion
:help popupmenu-keys

28 August 2021

Using Tabs in Vim

 Using tab in vim

 

https://www.linux.com/training-tutorials/vim-tips-using-tabs/

 

 1. Open a new tab for authoring a new text file

:tabnew

2. Open an existing file in a new tab


:tabf *abc

or

:tabf abc*

or

:tabf abc[tab]

f means find. Suppose that there is a file whose name is abcdef.txt. You type 'abc', then press the Tab key, system will automatically type in the rest of the file name for you.

3. Go to different tabs

gt - to the next tab.
gT - move to the previous tab.
g0 - move to the first tab.
g$ - move to the last tab.

ngt

n: 1 - the first tab; 2 - the second tab, and so on.

4. Moving a tab

:tabm n

n: 0 - the first tab; 1 - the second tab, and so on.

5. Running commands in all the opened tabs

e.g. if we want to substitute 'bar' for 'foo' in all the opened tabs, then

:tabdo %s/foo/bar/gc

5. To see a list of the files opened in all the tabs

:tabs


22 August 2021

Can open Excel files locally but not from network

 

Can open Excel files locally but not from network

Problem: 

Can open Excel files locally but not from network

Solution:

File -> Options -> Trust Centre -> Trust Centre Settings -> Protected View.

Clear all the ticks. Click OK.



16 August 2021

export pandas dataframe to html and appy css styles

 export pandas dataframe to html and appy css styles

 

 Ku Tang Pan

I found the most precise, and frankly the easiest way of doing it is skipping the styling, to_html() etc. and converting the DF to a dictionary using the df.to_dict() method.

Specifically what gave me trouble, was displaying the styled pandas html in an outlook email, as it just wouldn't render properly with the css mess that pandas was producing.

iterate over the dict and generate the html there by simply wrapping keys/values in the tags that you need, adding classes etc. and concatenate this all into one string. Then paste this str into a prepared template with a predefined css.

For convenience I found it's useful to export the same df twice, using .to_dict() and to_dict('index') to first fill in the columns and then work your way down row by row. Alternatively just have a list of relevant column names.

dict_data = [df.to_dict(), df.to_dict('index')]

return_str = '<table><tr>'

for key in dict_data[0].keys():
    return_str = return_str + '<th class="header">' + key + '</th>'

return_str = return_str + '</tr>'

for key in dict_data[1].keys():
    return_str = return_str + '<tr><th class="index">' + key + '</th>'
    for subkey in dict_data[1][key]:
        return_str = return_str + '<td>' + dict_data[1][key][subkey] + '</td>'

return_str = return_str + '</tr></table>'

and then return_str goes into the template.

 

10 August 2021

How to read a file, which only contains a string, into Python, and then convert the string into a list?

 How to read a file, which only contains a string, into Python, and then convert the string into a list?


from pathlib import Path

txt = Path('filename.txt').read_text()

list_ = list(txt.split('; '))

08 August 2021

How to convert a pandas dataframe into a python list, and a python list into a pandas dataframe?

 How to convert a pandas dataframe into a python list, and a python list into a pandas dataframe?


1. To convert a pandas dataframe into a python list

email_list = df['Email'].to_list()

or

email_list = df[['Name', 'Email']].to_list()


2. To convert a python list into a pandas dataframe

Examples

>>> mydict = [{'a': 1, 'b': 2, 'c': 3, 'd': 4},
...           {'a': 100, 'b': 200, 'c': 300, 'd': 400},
...           {'a': 1000, 'b': 2000, 'c': 3000, 'd': 4000 }]
>>> df = pd.DataFrame(mydict)
>>> df
      a     b     c     d
0     1     2     3     4
1   100   200   300   400
2  1000  2000  3000  4000