software:python
Differences
This shows you the differences between two versions of the page.
Both sides previous revisionPrevious revisionNext revision | Previous revision | ||
software:python [2020/12/26 19:49] – superwizard | software:python [2020/12/27 05:23] (current) – [Plotly] superwizard | ||
---|---|---|---|
Line 90: | Line 90: | ||
</ | </ | ||
- | |||
====== UCS-2 is UTF-16 ====== | ====== UCS-2 is UTF-16 ====== | ||
Line 132: | Line 131: | ||
+ | </ | ||
+ | |||
+ | ====== Atrribute errno ====== | ||
+ | |||
+ | <WRAP center round box > | ||
2020-07-16 | 2020-07-16 | ||
Line 142: | Line 146: | ||
+ | </ | ||
+ | |||
+ | ====== Cclasses Make an empty file called __init__.py ====== | ||
+ | |||
+ | <WRAP center round box > | ||
2020-07-05 | 2020-07-05 | ||
Line 166: | Line 175: | ||
+ | </ | ||
+ | |||
+ | ====== Python RegEx ====== | ||
+ | |||
+ | <WRAP center round box > | ||
2020-07-04 | 2020-07-04 | ||
Line 180: | Line 194: | ||
From < | From < | ||
+ | |||
+ | </ | ||
+ | |||
+ | ====== Discovering millions of datasets ====== | ||
+ | |||
+ | <WRAP center round box > | ||
2020-04-02 | 2020-04-02 | ||
Line 194: | Line 214: | ||
+ | </ | ||
+ | |||
+ | ====== Python Cheatsheet ====== | ||
+ | |||
+ | <WRAP center round box > | ||
2020-04-01 | 2020-04-01 | ||
Line 213: | Line 238: | ||
</ | </ | ||
+ | |||
+ | ====== Illustrated Guide to Python 3 ====== | ||
<WRAP center round box > | <WRAP center round box > | ||
Line 223: | Line 250: | ||
+ | </ | ||
+ | |||
+ | ====== retrieve all groups for a specific domain ====== | ||
+ | |||
+ | <WRAP center round box > | ||
2019-09--17 | 2019-09--17 | ||
Line 228: | Line 260: | ||
To retrieve all groups for a specific domain or the account, use the following GET request and include the authorization described in Authorize requests. For the query strings, request, and response properties, see the API Reference. For readability, | To retrieve all groups for a specific domain or the account, use the following GET request and include the authorization described in Authorize requests. For the query strings, request, and response properties, see the API Reference. For readability, | ||
+ | < | ||
GET https:// | GET https:// | ||
& | & | ||
& | & | ||
+ | </ | ||
When retrieving: | When retrieving: | ||
- | • All groups for a sub-domain — Use the domain argument with the domain' | + | • All groups for a sub-domain — Use the domain argument with the domain' |
- | • All groups for the account — Use the customer argument with either my_customer or the account' | + | |
- | • Using both domain and customer arguments — The API returns all the groups for the domain. | + | |
- | • Not using the domain and customer arguments — The API returns all the groups for the account associated with my_customer. This is the account customerId of the administrator making the API request. | + | |
From < | From < | ||
+ | </ | ||
+ | |||
+ | ====== APIs & Services ====== | ||
+ | |||
+ | <WRAP center round box > | ||
APIs & Services | APIs & Services | ||
Line 271: | Line 310: | ||
+ | </ | ||
+ | |||
+ | ====== Algorithms ====== | ||
+ | |||
+ | <WRAP center round box > | ||
2019-08-28 | 2019-08-28 | ||
Line 283: | Line 327: | ||
+ | </ | ||
+ | |||
+ | ====== You can still miss attachments ====== | ||
+ | |||
+ | <WRAP center round box > | ||
2019-08-23 | 2019-08-23 | ||
Line 293: | Line 342: | ||
From < | From < | ||
- | + | • Now with this service you can read your emails and read any attachments you may have in your e-mails | |
- | + | | |
- | • Now with this service you can read your emails and read any attachments you may have in your e-mails | + | |
- | • First you can query your e-mails with a search string to find the e-mail ids you need that have the attachments: | + | |
- | search_query = " | + | |
- | result = service.users().messages().list(userId=' | + | |
- | msgs = results[' | + | |
- | msg_ids = [msg[' | + | |
- | • now for each messageId you can find the associated attachments in the email. | + | |
From < | From < | ||
- | payload.headers[] list List of headers on this message part. For the top-level message part, representing the entire message payload, it will contain the standard RFC 2822 email headers such as To, | + | payload.headers[] list List of headers on this message part. For the top-level message part, representing the entire message payload, it will contain the standard RFC 2822 email headers such as To, |
From < | From < | ||
Line 313: | Line 360: | ||
- | headers=messageheader[" | + | headers=messageheader[" |
- | subject= [i[' | + | |
From < | From < | ||
Line 321: | Line 368: | ||
+ | </ | ||
+ | |||
+ | ====== the Gmail API ====== | ||
+ | |||
+ | <WRAP center round box > | ||
the Gmail API | the Gmail API | ||
Line 332: | Line 384: | ||
Example 3 | Example 3 | ||
+ | < | ||
import re re.sub(' | import re re.sub(' | ||
• string1 - Result: 3.11899876595 | • string1 - Result: 3.11899876595 | ||
• string2 - Result: 2.78014397621 | • string2 - Result: 2.78014397621 | ||
+ | </ | ||
From < | From < | ||
+ | </ | ||
+ | |||
+ | ====== Access Dates ====== | ||
+ | |||
+ | <WRAP center round box > | ||
Access Dates | Access Dates | ||
and then access the data using a loop: | and then access the data using a loop: | ||
+ | < | ||
for msg in msgs[' | for msg in msgs[' | ||
m_id = msg[' | m_id = msg[' | ||
Line 352: | Line 411: | ||
** DATA STORAGE FUNCTIONS ETC ** | ** DATA STORAGE FUNCTIONS ETC ** | ||
- | From <https:// | + | </code> |
+ | From < | ||
Line 361: | Line 421: | ||
From < | From < | ||
+ | </ | ||
+ | ====== Sort a Dictionary ====== | ||
- | + | <WRAP center round box > | |
2019-08-22 | 2019-08-22 | ||
Line 373: | Line 434: | ||
+ | </ | ||
+ | |||
+ | ====== Plotly Cufflinks ====== | ||
+ | |||
+ | <WRAP center round box > | ||
2019-08-15 | 2019-08-15 | ||
Line 383: | Line 449: | ||
From < | From < | ||
- | |||
- | |||
</ | </ | ||
- | <WRAP center round box 60%> | + | ====== Parsing text with Python ====== |
+ | |||
+ | <WRAP center round box > | ||
2019-07-11 | 2019-07-11 | ||
Line 401: | Line 467: | ||
+ | </ | ||
+ | |||
+ | ====== DataFrames ====== | ||
+ | |||
+ | <WRAP center round box > | ||
2019-08-14 | 2019-08-14 | ||
Line 410: | Line 481: | ||
+ | </ | ||
+ | |||
+ | ====== Backblaze ====== | ||
+ | |||
+ | <WRAP center round box > | ||
2019-7-11 | 2019-7-11 | ||
Line 426: | Line 502: | ||
+ | </ | ||
+ | |||
+ | ====== Plotly ====== | ||
+ | |||
+ | <WRAP center round box > | ||
2019-07-01 | 2019-07-01 | ||
+ | < | ||
import plotly.plotly as py | import plotly.plotly as py | ||
import plotly.graph_objs as go | import plotly.graph_objs as go | ||
Line 443: | Line 525: | ||
fig = go.Figure(data=data, | fig = go.Figure(data=data, | ||
py.iplot(fig, | py.iplot(fig, | ||
+ | |||
+ | |||
+ | </ | ||
From < | From < | ||
+ | </ | ||
+ | ====== Regular Expression ====== | ||
+ | |||
+ | |||
+ | <WRAP center round box > | ||
2019-05-29 | 2019-05-29 | ||
- | ValidIpAddressRegex = " | + | |
From < | From < | ||
+ | < | ||
\b(25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9]? | \b(25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9]? | ||
(25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9]? | (25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9]? | ||
(25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9]? | (25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9]? | ||
(25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9]? | (25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9]? | ||
+ | </ | ||
From < | From < | ||
Line 469: | Line 561: | ||
From < | From < | ||
+ | </ | ||
+ | ====== Split the string at the last occurrence of sep ====== | ||
- | + | <WRAP center round box > | |
2019-05-23 | 2019-05-23 | ||
- | str.rpartition(sep) | + | |
- | Split the string at the last occurrence of sep, and return a 3-tuple containing the part before the separator, the separator itself, and the part after the separator. If the separator is not found, return a 3-tuple containing two empty strings, followed by the string itself. | + | |
+ | Split the string at the last occurrence of sep, and return a 3-tuple containing the part before the separator, the separator itself, and the part after the separator. If the separator is not found, return a 3-tuple containing two empty strings, followed by the string itself. | ||
From < | From < | ||
+ | </ | ||
+ | ====== The built-in os module has a number of useful functions ====== | ||
+ | |||
+ | <WRAP center round box > | ||
The built-in os module has a number of useful functions that can be used to list directory contents and filter the results. To get a list of all the files and folders in a particular directory in the filesystem, use os.listdir() in legacy versions of Python or os.scandir() in Python 3.x. os.scandir() is the preferred method to use if you also want to get file and directory properties such as file size and modification date. | The built-in os module has a number of useful functions that can be used to list directory contents and filter the results. To get a list of all the files and folders in a particular directory in the filesystem, use os.listdir() in legacy versions of Python or os.scandir() in Python 3.x. os.scandir() is the preferred method to use if you also want to get file and directory properties such as file size and modification date. | ||
Line 486: | Line 584: | ||
+ | </ | ||
+ | |||
+ | ====== Splitting, Concatenating, | ||
+ | |||
+ | <WRAP center round box > | ||
2019-05-20 | 2019-05-20 | ||
Line 493: | Line 596: | ||
+ | </ | ||
+ | |||
+ | ====== Regex Testor ====== | ||
+ | |||
+ | <WRAP center round box > | ||
Regex Testor | Regex Testor | ||
Line 498: | Line 606: | ||
https:// | https:// | ||
+ | </ | ||
+ | |||
+ | ====== processdokuwikifile ====== | ||
+ | |||
+ | <WRAP center round box > | ||
2019-05-15 | 2019-05-15 | ||
+ | < | ||
def processdokuwikifile(in_file, | def processdokuwikifile(in_file, | ||
""" | """ | ||
- | #with open(' | + | #with open(' |
with open(par_out_file,' | with open(par_out_file,' | ||
out = csv.writer(out_file) | out = csv.writer(out_file) | ||
- | #with open(' | + | #with open(' |
- | #with open(' | + | #with open(' |
- | with open(in_file,' | + | with open(in_file,' |
+ | </ | ||
Line 528: | Line 643: | ||
From < | From < | ||
+ | </ | ||
+ | ====== PASS BY OBJECT REFERENCE (Case in python): ====== | ||
+ | <WRAP center round box > | ||
2019-04-08 | 2019-04-08 | ||
Line 535: | Line 653: | ||
PASS BY OBJECT REFERENCE (Case in python): | PASS BY OBJECT REFERENCE (Case in python): | ||
Here, " | Here, " | ||
+ | < | ||
def append_one(li): | def append_one(li): | ||
li.append(1) | li.append(1) | ||
Line 540: | Line 659: | ||
append_one(x) | append_one(x) | ||
print x | print x | ||
+ | </ | ||
+ | |||
Here, the statement x = [0] makes a variable x (box) that points towards the object [0] | Here, the statement x = [0] makes a variable x (box) that points towards the object [0] | ||
On the function being called, a new box li is created. The contents of li is the SAME as the contents of box x. Both the boxes contain the same object. That is, both the variables point to the same object in memory. Hence, any change to the object pointed at by li will also be reflected by the object pointed at by x. | On the function being called, a new box li is created. The contents of li is the SAME as the contents of box x. Both the boxes contain the same object. That is, both the variables point to the same object in memory. Hence, any change to the object pointed at by li will also be reflected by the object pointed at by x. | ||
Line 547: | Line 668: | ||
If the variable li is reassigned in the function, then li will point to a seperate object in memory. x however, will continue pointing to the same object in memory it was pointing to earlier. | If the variable li is reassigned in the function, then li will point to a seperate object in memory. x however, will continue pointing to the same object in memory it was pointing to earlier. | ||
Example: | Example: | ||
+ | < | ||
def append_one(li): | def append_one(li): | ||
li = [0, 1] | li = [0, 1] | ||
Line 552: | Line 674: | ||
append_one(x) | append_one(x) | ||
print x | print x | ||
+ | </ | ||
The output of the program will be: | The output of the program will be: | ||
[0] | [0] | ||
From < | From < | ||
+ | </ | ||
+ | ====== Plotly ====== | ||
+ | |||
+ | <WRAP center round box > | ||
2019-03-31 | 2019-03-31 | ||
Plotly | Plotly | ||
+ | < | ||
1962_2006_walmart_store_openings.csv Update 1962_2006_walmart_store_openings.csv 4 years ago | 1962_2006_walmart_store_openings.csv Update 1962_2006_walmart_store_openings.csv 4 years ago | ||
2010_alcohol_consumption_by_country.csv Create 2010_alcohol_consumption_by_country.csv 3 years ago | 2010_alcohol_consumption_by_country.csv Create 2010_alcohol_consumption_by_country.csv 3 years ago | ||
2011_february_aa_flight_paths.csv Create 2011_february_aa_flight_paths.csv 4 years ago | 2011_february_aa_flight_paths.csv Create 2011_february_aa_flight_paths.csv 4 years ago | ||
2011_february_us_airport_traffic.csv Create 2011_february_us_airport_traffic.csv 4 years ago | 2011_february_us_airport_traffic.csv Create 2011_february_us_airport_traffic.csv 4 years ago | ||
+ | </ | ||
From < | From < | ||
+ | </ | ||
+ | |||
+ | ====== Python write to CSV ====== | ||
+ | |||
+ | |||
+ | <WRAP center round box > | ||
2019-03-29 | 2019-03-29 | ||
Line 576: | Line 711: | ||
Python write to CSV | Python write to CSV | ||
+ | < | ||
import csv | import csv | ||
with open(..., ' | with open(..., ' | ||
wr = csv.writer(myfile, | wr = csv.writer(myfile, | ||
wr.writerow(mylist) | wr.writerow(mylist) | ||
+ | </ | ||
From < | From < | ||
+ | < | ||
with open(iniFile.absolute(), | with open(iniFile.absolute(), | ||
#spamwriter = csv.writer(iniSettings, | #spamwriter = csv.writer(iniSettings, | ||
Line 593: | Line 731: | ||
for val in folder_list: | for val in folder_list: | ||
spamwriter.writerow(val) | spamwriter.writerow(val) | ||
+ | </ | ||
you can also use wr.writerows(list) – tovmeod Dec 25 '11 at 22:29 | you can also use wr.writerows(list) – tovmeod Dec 25 '11 at 22:29 | ||
Line 599: | Line 738: | ||
From < | From < | ||
+ | </ | ||
+ | ====== CSV in Python adding an extra carriage return, on Windows ====== | ||
+ | |||
+ | <WRAP center round box > | ||
CSV in Python adding an extra carriage return, on Windows | CSV in Python adding an extra carriage return, on Windows | ||
One of the possible fixes in Python3, as described in @YiboYang' | One of the possible fixes in Python3, as described in @YiboYang' | ||
+ | < | ||
f = open(path_to_file, | f = open(path_to_file, | ||
writer = csv.writer(f) | writer = csv.writer(f) | ||
+ | </ | ||
From < | From < | ||
+ | </ | ||
+ | |||
+ | ====== Examples of simple type checking in Python: ====== | ||
+ | |||
+ | |||
+ | <WRAP center round box > | ||
2019-02-17 | 2019-02-17 | ||
Examples of simple type checking in Python: | Examples of simple type checking in Python: | ||
+ | < | ||
assert type(variable_name) == int | assert type(variable_name) == int | ||
assert type(variable_name) == bool | assert type(variable_name) == bool | ||
assert type(variable_name) == list | assert type(variable_name) == list | ||
+ | </ | ||
From < | From < | ||
Use type | Use type | ||
+ | < | ||
>>> | >>> | ||
<type ' | <type ' | ||
Line 625: | Line 779: | ||
>>> | >>> | ||
' | ' | ||
+ | </ | ||
From < | From < | ||
+ | </ | ||
+ | |||
+ | ====== isinstance() ====== | ||
+ | |||
+ | <WRAP center round box > | ||
With one argument, return the type of an object. The return value is a type object. The isinstance() built-in function is recommended for testing | With one argument, return the type of an object. The return value is a type object. The isinstance() built-in function is recommended for testing | ||
Line 633: | Line 793: | ||
• Syntax: | • Syntax: | ||
+ | < | ||
isinstance(object, | isinstance(object, | ||
+ | </ | ||
The isinstance() takes two parameters: | The isinstance() takes two parameters: | ||
+ | < | ||
object : object to be checked | object : object to be checked | ||
classinfo : class, type, or tuple of classes and types | classinfo : class, type, or tuple of classes and types | ||
+ | </ | ||
From < | From < | ||
+ | </ | ||
+ | ====== graph-cli ====== | ||
- | + | <WRAP center round box > | |
- | </ | + | |
- | + | ||
- | <WRAP center round box 60%> | + | |
2019-01-05 | 2019-01-05 | ||
Line 657: | Line 820: | ||
+ | </ | ||
+ | |||
+ | ====== copy2 ====== | ||
+ | |||
+ | <WRAP center round box > | ||
2018-12-25 | 2018-12-25 | ||
Line 663: | Line 831: | ||
As with the previous methods, | As with the previous methods, | ||
The syntax is as follows: | The syntax is as follows: | ||
+ | < | ||
shutil.copy2(src_file, | shutil.copy2(src_file, | ||
+ | </ | ||
From < | From < | ||
+ | </ | ||
+ | |||
+ | ====== Start of String Only: \A ====== | ||
+ | |||
+ | <WRAP center round box > | ||
Start of String Only: \A | Start of String Only: \A | ||
Line 672: | Line 847: | ||
From < | From < | ||
+ | |||
+ | </ | ||
+ | |||
+ | ====== Decimals interact well with much of the rest of Python ====== | ||
+ | |||
+ | <WRAP center round box > | ||
decimal — Decimal fixed point and floating point arithmetic | decimal — Decimal fixed point and floating point arithmetic | ||
Line 678: | Line 859: | ||
Unlike hardware based binary floating point, the decimal module has a user alterable precision (defaulting to 28 places) which can be as large as needed for a given problem: | Unlike hardware based binary floating point, the decimal module has a user alterable precision (defaulting to 28 places) which can be as large as needed for a given problem: | ||
+ | < | ||
>>> | >>> | ||
>>> | >>> | ||
Line 685: | Line 867: | ||
>>> | >>> | ||
Decimal(' | Decimal(' | ||
+ | </ | ||
From < | From < | ||
Decimals interact well with much of the rest of Python. Here is a small decimal floating point flying circus: | Decimals interact well with much of the rest of Python. Here is a small decimal floating point flying circus: | ||
+ | < | ||
>>> | >>> | ||
>>> | >>> | ||
Line 697: | Line 881: | ||
[Decimal(' | [Decimal(' | ||
| | ||
+ | </ | ||
From < | From < | ||
+ | |||
+ | </ | ||
+ | |||
+ | ====== splitting a number into the integer and decimal parts ====== | ||
+ | |||
+ | <WRAP center round box > | ||
+ | |||
splitting a number into the integer and decimal parts | splitting a number into the integer and decimal parts | ||
+ | < | ||
>>> | >>> | ||
>>> | >>> | ||
Line 709: | Line 902: | ||
147.0 | 147.0 | ||
>>> | >>> | ||
+ | </ | ||
If you want the integer part as an integer and not a float, use int(a// | If you want the integer part as an integer and not a float, use int(a// | ||
EDIT: Remember that the decimal part of a float number is approximate, | EDIT: Remember that the decimal part of a float number is approximate, | ||
Line 714: | Line 908: | ||
From < | From < | ||
+ | < | ||
import math | import math | ||
x = 1234.5678 | x = 1234.5678 | ||
math.modf(x) # (0.5678000000000338, | math.modf(x) # (0.5678000000000338, | ||
+ | </ | ||
From < | From < | ||
Line 722: | Line 918: | ||
Create a date object: | Create a date object: | ||
+ | < | ||
import datetime | import datetime | ||
x = datetime.datetime(2020, | x = datetime.datetime(2020, | ||
+ | </ | ||
From < | From < | ||
+ | </ | ||
+ | |||
+ | ====== Module datetime provides ====== | ||
+ | |||
+ | <WRAP center round box > | ||
Module datetime provides classes for manipulating date and time in more object oriented way. One of them is datetime.datetime.now which return number of seconds since the epoch. | Module datetime provides classes for manipulating date and time in more object oriented way. One of them is datetime.datetime.now which return number of seconds since the epoch. | ||
+ | < | ||
import datetime; | import datetime; | ||
ts = datetime.datetime.now().timestamp() | ts = datetime.datetime.now().timestamp() | ||
print(ts) | print(ts) | ||
# 1545665588.52 | # 1545665588.52 | ||
+ | </ | ||
+ | |||
From < | From < | ||
+ | < | ||
x = int(datetime.datetime(2070, | x = int(datetime.datetime(2070, | ||
print(x) | print(x) | ||
+ | </ | ||
+ | </ | ||
+ | |||
+ | ====== Example 2: Right justify string and fill the remaining spaces ====== | ||
+ | |||
+ | <WRAP center round box > | ||
Example 2: Right justify string and fill the remaining spaces | Example 2: Right justify string and fill the remaining spaces | ||
+ | < | ||
# example string | # example string | ||
string = ' | string = ' | ||
Line 751: | Line 965: | ||
# print right justified string | # print right justified string | ||
print(string.rjust(width, | print(string.rjust(width, | ||
+ | </ | ||
From < | From < | ||
+ | </ | ||
+ | ====== Practical Business Python ====== | ||
+ | <WRAP center round box > | ||
2018-12-24 | 2018-12-24 | ||
Practical Business Python | Practical Business Python | ||
- | |||
pbpython/ | pbpython/ | ||
Line 767: | Line 983: | ||
+ | </ | ||
+ | ====== The divmod() returns ====== | ||
+ | <WRAP center round box > | ||
Line 778: | Line 997: | ||
From < | From < | ||
+ | </ | ||
+ | |||
+ | ====== numpy ====== | ||
+ | |||
+ | <WRAP center round box > | ||
2018-11-18 | 2018-11-18 | ||
+ | < | ||
pip install numpy | pip install numpy | ||
+ | </ | ||
From < | From < | ||
+ | < | ||
pip3.6 install numpy | pip3.6 install numpy | ||
pip3.6 install scipy | pip3.6 install scipy | ||
Line 791: | Line 1018: | ||
Install opencv-python instead of cv2. | Install opencv-python instead of cv2. | ||
pip install opencv-python | pip install opencv-python | ||
+ | </ | ||
From < | From < | ||
+ | </ | ||
+ | |||
+ | ====== compare the use of lambda ====== | ||
+ | |||
+ | <WRAP center round box > | ||
Line 801: | Line 1034: | ||
From < | From < | ||
+ | </ | ||
+ | |||
+ | ====== Key Functions ====== | ||
+ | |||
+ | <WRAP center round box > | ||
Key Functions | Key Functions | ||
Line 816: | Line 1054: | ||
This image was created with the following code. | This image was created with the following code. | ||
+ | < | ||
1 import operator | 1 import operator | ||
2 import pylab | 2 import pylab | ||
Line 843: | Line 1082: | ||
26 pylab.grid() | 26 pylab.grid() | ||
27 pylab.title(" | 27 pylab.title(" | ||
+ | </ | ||
From < | From < | ||
Line 848: | Line 1088: | ||
As already said, | As already said, | ||
Change: | Change: | ||
+ | < | ||
key=lambda(k, | key=lambda(k, | ||
+ | </ | ||
To: | To: | ||
+ | < | ||
key=lambda k, v: sort_order.index(k) | key=lambda k, v: sort_order.index(k) | ||
+ | </ | ||
From < | From < | ||
Line 857: | Line 1101: | ||
</ | </ | ||
- | <WRAP center round box 60%> | + | ====== What problem does pandas solve? ====== |
+ | |||
+ | <WRAP center round box > | ||
2018-11-15 | 2018-11-15 | ||
Line 867: | Line 1113: | ||
NumPy | NumPy | ||
+ | < | ||
NumPy is the fundamental package for scientific computing with Python. It contains among other things: | NumPy is the fundamental package for scientific computing with Python. It contains among other things: | ||
• a powerful N-dimensional array object | • a powerful N-dimensional array object | ||
Line 872: | Line 1119: | ||
• tools for integrating C/C++ and Fortran code | • tools for integrating C/C++ and Fortran code | ||
• useful linear algebra, Fourier transform, and random number capabilities | • useful linear algebra, Fourier transform, and random number capabilities | ||
+ | </ | ||
From < | From < | ||
Line 878: | Line 1126: | ||
From < | From < | ||
+ | |||
+ | </ | ||
+ | |||
+ | ====== scikit-learn ====== | ||
+ | |||
+ | <WRAP center round box > | ||
scikit-learn | scikit-learn | ||
Line 893: | Line 1147: | ||
From < | From < | ||
+ | </ | ||
+ | ====== python read fails on special characters ====== | ||
+ | <WRAP center round box > | ||
2018-11-06 | 2018-11-06 | ||
Line 908: | Line 1165: | ||
From < | From < | ||
+ | </ | ||
+ | ====== idle args ====== | ||
+ | |||
+ | <WRAP center round box > | ||
2018-10-31 | 2018-10-31 | ||
Line 923: | Line 1184: | ||
Pending application of a patch, the following will work to only add args to sys.argv when running from an Idle editor. | Pending application of a patch, the following will work to only add args to sys.argv when running from an Idle editor. | ||
+ | < | ||
import sys | import sys | ||
# ... | # ... | ||
Line 937: | Line 1199: | ||
except: | except: | ||
sys.argv = [sys.argv[0], | sys.argv = [sys.argv[0], | ||
+ | </ | ||
From < | From < | ||
+ | </ | ||
+ | ====== Auto detect IDLE and prompt for command-line argument values ====== | ||
+ | |||
+ | |||
+ | <WRAP center round box > | ||
2018-10-31 | 2018-10-31 | ||
Line 946: | Line 1214: | ||
Auto detect IDLE and prompt for command-line argument values | Auto detect IDLE and prompt for command-line argument values | ||
- | #! / | + | < |
+ | c#! / | ||
import sys | import sys | ||
def ok(x=None): | def ok(x=None): | ||
Line 962: | Line 1231: | ||
root.bind("< | root.bind("< | ||
e.focus() | e.focus() | ||
+ | </ | ||
From < | From < | ||
+ | </ | ||
+ | |||
+ | ====== print the files deleted ====== | ||
+ | |||
+ | <WRAP center round box > | ||
Line 970: | Line 1245: | ||
Python Script | Python Script | ||
Here's a Python script that will also print the files deleted | Here's a Python script that will also print the files deleted | ||
+ | < | ||
import os | import os | ||
for line in open(" | for line in open(" | ||
Line 981: | Line 1257: | ||
except OSError: | except OSError: | ||
pass | pass | ||
+ | </ | ||
+ | |||
+ | </ | ||
+ | |||
+ | ====== delete directories ====== | ||
+ | |||
+ | <WRAP center round box > | ||
Here's an alternative Python script that is case sensitive and will also delete directories included in the list | Here's an alternative Python script that is case sensitive and will also delete directories included in the list | ||
+ | < | ||
import os | import os | ||
import shutil | import shutil | ||
Line 1006: | Line 1290: | ||
# | # | ||
pass | pass | ||
+ | </ | ||
From < | From < | ||
+ | </ | ||
+ | |||
+ | ====== checkpoints ====== | ||
+ | |||
+ | <WRAP center round box > | ||
2018-10-06 | 2018-10-06 | ||
GLOB | GLOB | ||
+ | < | ||
def delete_previous_checkpoints(self, | def delete_previous_checkpoints(self, | ||
""" | """ | ||
Line 1030: | Line 1321: | ||
ckpt_file_nm = self.get_checkpoint_location() + '/ | ckpt_file_nm = self.get_checkpoint_location() + '/ | ||
os.remove(ckpt_file_nm) | os.remove(ckpt_file_nm) | ||
+ | </ | ||
From < | From < | ||
+ | </ | ||
+ | ====== argparse ====== | ||
+ | <WRAP center round box > | ||
2018-10-06 | 2018-10-06 | ||
Line 1041: | Line 1336: | ||
From < | From < | ||
+ | </ | ||
+ | |||
+ | ====== Argparse Tutorial ====== | ||
+ | |||
+ | |||
+ | <WRAP center round box > | ||
Argparse Tutorial | Argparse Tutorial | ||
Line 1048: | Line 1349: | ||
From < | From < | ||
+ | < | ||
*args and **kwargs in Python | *args and **kwargs in Python | ||
*args | *args | ||
+ | </ | ||
The special syntax *args in function definitions in python is used to pass a variable number of arguments to a function. It is used to pass a non-keyworded, | The special syntax *args in function definitions in python is used to pass a variable number of arguments to a function. It is used to pass a non-keyworded, | ||
Line 1055: | Line 1358: | ||
+ | </ | ||
+ | |||
+ | ====== recursive ====== | ||
+ | |||
+ | <WRAP center round box > | ||
2018-10-03 | 2018-10-03 | ||
Line 1064: | Line 1372: | ||
From < | From < | ||
+ | I have successfully used | ||
+ | < | ||
+ | for i in d.rglob(' | ||
+ | </ | ||
+ | |||
+ | < | ||
for i in d.iglob(' | for i in d.iglob(' | ||
+ | </ | ||
The “**” pattern means “this directory and all subdirectories, | The “**” pattern means “this directory and all subdirectories, | ||
Line 1070: | Line 1385: | ||
From < | From < | ||
+ | < | ||
errno.ENOTEMPTY | errno.ENOTEMPTY | ||
Directory not empty | Directory not empty | ||
+ | </ | ||
From < | From < | ||
+ | < | ||
errno.EACCES¶ | errno.EACCES¶ | ||
Permission denied | Permission denied | ||
+ | </ | ||
From < | From < | ||
+ | < | ||
except OSError as e: | except OSError as e: | ||
if e.errno not in _IGNORED_ERROS: | if e.errno not in _IGNORED_ERROS: | ||
raise | raise | ||
return False | return False | ||
+ | </ | ||
From < | From < | ||
+ | < | ||
except OSError as e: | except OSError as e: | ||
if e.errno != EINVAL and strict: | if e.errno != EINVAL and strict: | ||
raise | raise | ||
+ | </ | ||
From < | From < | ||
+ | </ | ||
+ | |||
+ | ====== walktree ====== | ||
+ | |||
+ | <WRAP center round box > | ||
2018-10-01 | 2018-10-01 | ||
Line 1120: | Line 1448: | ||
+ | </ | ||
+ | |||
+ | ====== Dropbox in python ====== | ||
+ | |||
+ | |||
+ | |||
+ | <WRAP center round box > | ||
2018-09-29 | 2018-09-29 | ||
Dropbox in python | Dropbox in python | ||
+ | < | ||
from pathlib import Path | from pathlib import Path | ||
import arrow | import arrow | ||
Line 1136: | Line 1471: | ||
#remove it | #remove it | ||
pass | pass | ||
+ | </ | ||
From < | From < | ||
Line 1144: | Line 1479: | ||
From < | From < | ||
+ | </ | ||
+ | |||
+ | ====== CSV Toolkit Overview ====== | ||
+ | |||
+ | |||
+ | <WRAP center round box > | ||
2018-09-04 | 2018-09-04 | ||
Line 1152: | Line 1493: | ||
From < | From < | ||
+ | </ | ||
+ | |||
+ | ====== What is Bonobo? ====== | ||
+ | |||
+ | <WRAP center round box > | ||
What is Bonobo? | What is Bonobo? | ||
Bonobo is a lightweight Extract-Transform-Load (ETL) framework for Python 3.5+. | Bonobo is a lightweight Extract-Transform-Load (ETL) framework for Python 3.5+. | ||
Line 1163: | Line 1509: | ||
From < | From < | ||
+ | </ | ||
+ | |||
+ | ====== Awesome Python ====== | ||
+ | |||
+ | <WRAP center round box > | ||
Awesome Python | Awesome Python | ||
A curated list of awesome Python frameworks, libraries, software and resources. | A curated list of awesome Python frameworks, libraries, software and resources. | ||
Line 1178: | Line 1529: | ||
From < | From < | ||
+ | </ | ||
+ | ====== Python data visualization: | ||
+ | |||
+ | <WRAP center round box > | ||
2018-09-04 | 2018-09-04 | ||
Line 1187: | Line 1542: | ||
From < | From < | ||
+ | </ | ||
+ | ====== Best way to sort txt file using csv tools in python ====== | ||
+ | |||
+ | |||
+ | <WRAP center round box > | ||
2018-09-04 | 2018-09-04 | ||
Line 1195: | Line 1555: | ||
From < | From < | ||
+ | < | ||
import csv | import csv | ||
import operator | import operator | ||
Line 1211: | Line 1572: | ||
sortedlist=sorted(f, | sortedlist=sorted(f, | ||
print(sortedlist) | print(sortedlist) | ||
+ | </ | ||
From < | From < | ||
Line 1218: | Line 1580: | ||
2018-08-10 | 2018-08-10 | ||
The sys.path list contains the list of directories which will be searched for modules at runtime: | The sys.path list contains the list of directories which will be searched for modules at runtime: | ||
+ | < | ||
python -v | python -v | ||
>>> | >>> | ||
>>> | >>> | ||
['', | ['', | ||
+ | |||
+ | </ | ||
From < | From < | ||
For speedtest - / | For speedtest - / | ||
- | |||
</ | </ | ||
software/python.1609012161.txt.gz · Last modified: 2020/12/26 19:49 by superwizard