This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def example_fun(param0, param1): | |
""" | |
Does what | |
:param param0: | |
:param param1: | |
:return: | |
:raises: |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def multiplier(num1: float, num2: float) -> float: | |
"""Multiply two numbers to get their product. | |
:param num1: float, first number for multiplication | |
:param num2: float, second number for multiplication | |
:return: float, the product of the two numbers | |
""" | |
return num1 * num2 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Student: | |
def __init__(self, name, age): | |
self.name = name | |
self.age = age | |
def __repr__(self): | |
return f"Student({self.name!r}, {self.age})" | |
def __str__(self): | |
return f"Student Name: {self.name}; Age: {self.age}" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Student: | |
def __init__(self, name, age): | |
self.name = name | |
self.age = age | |
def __repr__(self): | |
return "Student __repr__ string" | |
def __str__(self): | |
return "Student __str__ string" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
>>> name = "Danny" | |
>>> age = 15 | |
>>> student = {"name": name} | |
>>> scores = [100, 99, 95] | |
>>> location = ('123 Main', 'NY') | |
>>> for item in (name, age, student, scores, location): | |
... print(f"{type(item)!s: <15}| repr: {repr(item): <20}| str: {str(item)}") | |
... | |
<class 'str'> | repr: 'Danny' | str: Danny | |
<class 'int'> | repr: 15 | str: 15 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
>>> data = {"timestamp": ["01/01/2022 09:01:00", "01/02/2022 08:55:44", "05/01/2022 22:01:00"], | |
... "category": list('ABC')} | |
>>> df = pd.DataFrame(data) | |
>>> df.dtypes | |
timestamp object | |
category object | |
dtype: object | |
>>> df["timestamp"] = pd.to_datetime(df["timestamp"]) | |
>>> df.dtypes | |
timestamp datetime64[ns] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
>>> pd.date_range(start="12/01/2022", end="12/07/2022") | |
DatetimeIndex(['2022-12-01', '2022-12-02', '2022-12-03', '2022-12-04', | |
'2022-12-05', '2022-12-06', '2022-12-07'], | |
dtype='datetime64[ns]', freq='D') |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
>>> import datetime | |
>>> start_date = datetime.datetime(2022, 12, 1) | |
>>> one_week = [start_date + datetime.timedelta(days=x) for x in range(7)] | |
>>> pd.DatetimeIndex(one_week) | |
DatetimeIndex(['2022-12-01', '2022-12-02', '2022-12-03', '2022-12-04', | |
'2022-12-05', '2022-12-06', '2022-12-07'], | |
dtype='datetime64[ns]', freq=None) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
>>> pd.to_datetime("Jan 01, 2022") | |
Timestamp('2022-01-01 00:00:00') | |
>>> pd.to_datetime(["01/01/2022", "01/02/2022", "01/03/2022"]) | |
DatetimeIndex(['2022-01-01', '2022-01-02', '2022-01-03'], dtype='datetime64[ns]', freq=None) | |
>>> pd.to_datetime(pd.Series(["01/01/2022", "01/02/2022", "01/03/2022"])) | |
0 2022-01-01 | |
1 2022-01-02 | |
2 2022-01-03 | |
dtype: datetime64[ns] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
>>> from datetime import datetime | |
>>> pd.read_csv("custom_dt_fmt.csv", parse_dates=["date"], date_parser=lambda x: datetime.strptime(x, "%b_%d_%Y")) | |
date category balance | |
0 2022-01-01 A 100 | |
1 2022-02-02 B 200 | |
2 2022-03-12 C 300 |