Skip to content

Commit 3b033d4

Browse files
committed
Datetime, Bytes, Struct, Numpy, Audio, Pygame, Pandas
1 parent cd41859 commit 3b033d4

File tree

2 files changed

+70
-70
lines changed

2 files changed

+70
-70
lines changed

README.md

Lines changed: 34 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -655,9 +655,9 @@ from dateutil.tz import tzlocal, gettz
655655
### Arithmetics
656656
```python
657657
<bool> = <D/T/DTn> > <D/T/DTn> # Ignores time jumps (fold attribute). Also ==.
658-
<bool> = <DTa> > <DTa> # Ignores time jumps if they share tzinfo object.
658+
<bool> = <DTa> > <DTa> # Ignores jumps if they share tz object. Broken ==.
659659
<TD> = <D/DTn> - <D/DTn> # Ignores jumps. Convert to UTC for actual delta.
660-
<TD> = <DTa> - <DTa> # Ignores time jumps if they share tzinfo object.
660+
<TD> = <DTa> - <DTa> # Ignores jumps if they share tzinfo object.
661661
<D/DT> = <D/DT> ± <TD> # Returned datetime can fall into missing hour.
662662
<TD> = <TD> * <float> # Also: <TD> = abs(<TD>) and <TD> = <TD> ±% <TD>.
663663
<float> = <TD> / <TD> # How many hours/weeks/years are in TD. Also //.
@@ -1951,26 +1951,26 @@ Bytes
19511951
**Bytes object is an immutable sequence of single bytes. Mutable version is called bytearray.**
19521952

19531953
```python
1954-
<bytes> = b'<str>' # Only accepts ASCII characters and \x00-\xff.
1955-
<int> = <bytes>[<index>] # Returns an int in range from 0 to 255.
1956-
<bytes> = <bytes>[<slice>] # Returns bytes even if it has only one element.
1957-
<bytes> = <bytes>.join(<coll_of_bytes>) # Joins elements using bytes as a separator.
1954+
<bytes> = b'<str>' # Only accepts ASCII characters and \x00-\xff.
1955+
<int> = <bytes>[<index>] # Returns an int in range from 0 to 255.
1956+
<bytes> = <bytes>[<slice>] # Returns bytes even if it has only one element.
1957+
<bytes> = <bytes>.join(<coll_of_bytes>) # Joins elements using bytes as a separator.
19581958
```
19591959

19601960
### Encode
19611961
```python
1962-
<bytes> = bytes(<coll_of_ints>) # Ints must be in range from 0 to 255.
1963-
<bytes> = bytes(<str>, 'utf-8') # Or: <str>.encode('utf-8')
1964-
<bytes> = <int>.to_bytes(n_bytes, …) # `byteorder='big/little', signed=False`.
1965-
<bytes> = bytes.fromhex('<hex>') # Hex pairs can be separated by whitespaces.
1962+
<bytes> = bytes(<coll_of_ints>) # Ints must be in range from 0 to 255.
1963+
<bytes> = bytes(<str>, 'utf-8') # Or: <str>.encode('utf-8')
1964+
<bytes> = <int>.to_bytes(n_bytes, …) # `byteorder='big/little', signed=False`.
1965+
<bytes> = bytes.fromhex('<hex>') # Hex pairs can be separated by whitespaces.
19661966
```
19671967

19681968
### Decode
19691969
```python
1970-
<list> = list(<bytes>) # Returns ints in range from 0 to 255.
1971-
<str> = str(<bytes>, 'utf-8') # Or: <bytes>.decode('utf-8')
1972-
<int> = int.from_bytes(<bytes>, …) # `byteorder='big/little', signed=False`.
1973-
'<hex>' = <bytes>.hex() # Returns hex pairs. Accepts `sep=<str>`.
1970+
<list> = list(<bytes>) # Returns ints in range from 0 to 255.
1971+
<str> = str(<bytes>, 'utf-8') # Or: <bytes>.decode('utf-8')
1972+
<int> = int.from_bytes(<bytes>, …) # `byteorder='big/little', signed=False`.
1973+
'<hex>' = <bytes>.hex() # Returns hex pairs. Accepts `sep=<str>`.
19741974
```
19751975

19761976
### Read Bytes from File
@@ -2009,12 +2009,12 @@ b'\x00\x01\x00\x02\x00\x00\x00\x03'
20092009
### Format
20102010
#### For standard type sizes and manual alignment (padding) start format string with:
20112011
* **`'='` - System's byte order (usually little-endian).**
2012-
* **`'<'` - Little-endian.**
2012+
* **`'<'` - Little-endian (i.e. least significant byte first).**
20132013
* **`'>'` - Big-endian (also `'!'`).**
20142014

20152015
#### Besides numbers, pack() and unpack() also support bytes objects as part of the sequence:
20162016
* **`'c'` - A bytes object with a single element. For pad byte use `'x'`.**
2017-
* **`'<n>s'` - A bytes object with n elements.**
2017+
* **`'<n>s'` - A bytes object with n elements (not effected by byte order).**
20182018

20192019
#### Integer types. Use a capital letter for unsigned type. Minimum and standard sizes are in brackets:
20202020
* **`'b'` - char (1/1)**
@@ -2414,7 +2414,7 @@ plt.clf() # Clears the figure.
24142414

24152415
Table
24162416
-----
2417-
#### Prints a CSV file as an ASCII table:
2417+
#### Prints a CSV spreadsheet to the console:
24182418
```python
24192419
# $ pip3 install tabulate
24202420
import csv, tabulate
@@ -2676,7 +2676,7 @@ import numpy as np
26762676
<array> = np.tile/repeat(<array>, <int/list> [, axis]) # Tiles array or repeats its elements.
26772677
```
26782678
* **Shape is a tuple of dimension sizes. A 100x50 RGB image has shape (50, 100, 3).**
2679-
* **Axis is an index of the dimension that gets aggregated. Leftmost dimension has index 0. Summing the RGB image along axis 2 will return a greyscale image with shape (50, 100).**
2679+
* **Axis is an index of a dimension. Leftmost dimension has index 0. Summing the RGB image along axis 2 will return a greyscale image with shape (50, 100).**
26802680

26812681
### Indexing
26822682
```perl
@@ -2858,21 +2858,21 @@ import wave
28582858
```
28592859

28602860
```python
2861-
<Wave> = wave.open('<path>', 'rb') # Opens the WAV file.
2862-
<int> = <Wave>.getframerate() # Returns number of frames per second.
2863-
<int> = <Wave>.getnchannels() # Returns number of samples per frame.
2864-
<int> = <Wave>.getsampwidth() # Returns number of bytes per sample.
2865-
<params> = <Wave>.getparams() # Returns collection of listed params.
2866-
<bytes> = <Wave>.readframes(nframes) # Returns next n frames. All if -1.
2861+
<Wave> = wave.open('<path>', 'rb') # Opens the WAV file.
2862+
<int> = <Wave>.getframerate() # Returns number of frames per second.
2863+
<int> = <Wave>.getnchannels() # Returns number of samples per frame.
2864+
<int> = <Wave>.getsampwidth() # Returns number of bytes per sample.
2865+
<tuple> = <Wave>.getparams() # Returns namedtuple of all parameters.
2866+
<bytes> = <Wave>.readframes(nframes) # Returns next n frames. All if -1.
28672867
```
28682868

28692869
```python
2870-
<Wave> = wave.open('<path>', 'wb') # Opens WAV file for writing.
2871-
<Wave>.setframerate(<int>) # Pass 44100 for CD, 48000 for video.
2872-
<Wave>.setnchannels(<int>) # Pass 1 for mono, 2 for stereo.
2873-
<Wave>.setsampwidth(<int>) # Pass 2 for CD, 3 for hi-res sound.
2874-
<Wave>.setparams(<params>) # Sets all parameters.
2875-
<Wave>.writeframes(<bytes>) # Appends frames to the file.
2870+
<Wave> = wave.open('<path>', 'wb') # Creates/truncates a file for writing.
2871+
<Wave>.setframerate(<int>) # Pass 44100 for CD, 48000 for video.
2872+
<Wave>.setnchannels(<int>) # Pass 1 for mono, 2 for stereo.
2873+
<Wave>.setsampwidth(<int>) # Pass 2 for CD, 3 for hi-res sound.
2874+
<Wave>.setparams(<tuple>) # Sets all parameters.
2875+
<Wave>.writeframes(<bytes>) # Appends frames to the file.
28762876
```
28772877
* **Bytes object contains a sequence of frames, each consisting of one or more samples.**
28782878
* **In a stereo signal, the first sample of a frame belongs to the left channel.**
@@ -3007,7 +3007,7 @@ while not pg.event.get(pg.QUIT):
30073007

30083008
```python
30093009
<bool> = <Rect>.collidepoint((x, y)) # Checks if rectangle contains the point.
3010-
<bool> = <Rect>.colliderect(<Rect>) # Checks if two rectangles overlap.
3010+
<bool> = <Rect>.colliderect(<Rect>) # Checks if the two rectangles overlap.
30113011
<int> = <Rect>.collidelist(<list_of_Rect>) # Returns index of first colliding Rect or -1.
30123012
<list> = <Rect>.collidelistall(<list_of_Rect>) # Returns indexes of all colliding rectangles.
30133013
```
@@ -3025,7 +3025,7 @@ while not pg.event.get(pg.QUIT):
30253025
```python
30263026
<Surf>.fill(color) # Tuple, Color('#rrggbb[aa]') or Color(<name>).
30273027
<Surf>.set_at((x, y), color) # Updates pixel. Also <Surf>.get_at((x, y)).
3028-
<Surf>.blit(<Surf>, (x, y)) # Draws passed surface to the surface.
3028+
<Surf>.blit(<Surf>, (x, y)) # Draws passed surface at specified location.
30293029
```
30303030

30313031
```python
@@ -3051,7 +3051,7 @@ rect(<Surf>, color, <Rect>, width=0) # Also polygon(<Surf>, color, po
30513051
### Sound
30523052
```python
30533053
<Sound> = pg.mixer.Sound(<path/file/bytes>) # WAV file or bytes/array of signed shorts.
3054-
<Sound>.play/stop() # Also <Sound>.set_volume(<float>).
3054+
<Sound>.play/stop() # Also set_volume(<float>), fadeout(msec).
30553055
```
30563056

30573057
### Basic Mario Brothers Example
@@ -3373,7 +3373,7 @@ c 7 8 6
33733373
<GB> = <DF>.groupby(column_key/s) # Splits DF into groups based on passed column.
33743374
<DF> = <GB>.apply(<func>) # Maps each group. Func can return DF, Sr or el.
33753375
<GB> = <GB>[column_key] # Single column GB. All operations return a Sr.
3376-
<Sr> = <GB>.size() # A Sr of group sizes. Keys are group "names".
3376+
<Sr> = <GB>.size() # A Sr of group sizes. Same keys as get_group().
33773377
```
33783378

33793379
#### GroupBy — Aggregate, Transform, Map:

0 commit comments

Comments
 (0)