- github.io guide - How to get started with github pages.
- markdown guide - Quick examples of markdown language
- Yong's Python notebook - Yong's notebook on Python
- github markdown guide - Guide to mastering markdown
The launcher allows Python scripts (.py and .pyw files) on Windows to specify the version of Python which should be used, allowing simultaneous use of Python 2 and 3.
Windows CMD, key in py -2 xy123.py
to run python code using version 2.7. Key in py -3 xy123.py
to run with version 3.7
Key in below in Win CMD to add pip path to environment variables.
setx PATH "%PATH%;C:\python37\Scripts"
Upgrade pip using:
py -3 -m pip install --upgrade pip
Without downloading package, install from internet:
py -3 -m pip install requests
You often want to send some sort of data in the URL’s query string. If you were constructing the URL by hand, this data would be given as key/value pairs in the URL after a question mark, e.g. httpbin.org/get?key=val. Requests allows you to provide these arguments as a dictionary of strings, using the params keyword argument. As an example, if you wanted to pass key1=value1 and key2=value2 to httpbin.org/get, you would use the following code:
payload = {'key1': 'value1', 'key2': 'value2'}
r = requests.get('https://httpbin.org/get', params=payload)
You can see that the URL has been correctly encoded by printing the URL:
print(r.url)
https://httpbin.org/get?key2=value2&key1=value1
Note that any dictionary key whose value is None will not be added to the URL’s query string.
You can also pass a list of items as a value:
payload = {'key1': 'value1', 'key2': ['value2', 'value3']}
r = requests.get('https://httpbin.org/get', params=payload)
print(r.url)
https://httpbin.org/get?key1=value1&key2=value2&key2=value3
Data Types: df.dtypes
Below with open method opens a .csv
file with 'a'
to append data to file. Opening the .csv
file the dataframe will be organized based on its delimiter. This means no need to delimit the file. However somehow it introduces empty rows after each data row.
with open method will automatically 'close'.
with open('test.csv', 'a') as f:'
df3.to_csv(f, header=False, index=False)`
Below implementation of to_csv
will create a file with default separator "," between attributes and looks very close to CSV format.
df3.to_csv('test1', header=False, index=False)
Using import datetime
package:
today = dt.datetime.utcnow()
df3['UpdateDate'] = today
Using import pandas as pd
package:
today = pd.Timestamp.utcnow()
df3['UpdateDate'] = today
Example below:
df3.rename(columns={'Last Price': 'LastPrice'}, inplace=True)
df3.rename(columns={'% Change': 'ChgPct'}, inplace=True)
df3['ChgPct'] = df3['ChgPct'].astype(float)