Finance
Finance-specific data cleaning functions.
convert_currency(df, api_key, column_name=None, from_currency=None, to_currency=None, historical_date=None, make_new_column=False)
Deprecated function.
Source code in janitor/finance.py
405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 |
|
convert_stock(stock_symbol)
This function takes in a stock symbol as a parameter, queries an API for the companies full name and returns it
Examples:
```python
import janitor.finance
janitor.finance.convert_stock("aapl")
```
Parameters:
Name | Type | Description | Default |
---|---|---|---|
stock_symbol
|
str
|
Stock ticker Symbol |
required |
Raises:
Type | Description |
---|---|
ConnectionError
|
Internet connection is not available |
Returns:
Type | Description |
---|---|
str
|
Full company name |
Source code in janitor/finance.py
697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 |
|
get_symbol(symbol)
This is a helper function to get a companies full name based on the stock symbol.
Examples:
```python
import janitor.finance
janitor.finance.get_symbol("aapl")
```
Parameters:
Name | Type | Description | Default |
---|---|---|---|
symbol
|
str
|
This is our stock symbol that we use to query the api for the companies full name. |
required |
Returns:
Type | Description |
---|---|
Optional[str]
|
Company full name |
Source code in janitor/finance.py
728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 |
|
inflate_currency(df, column_name=None, country=None, currency_year=None, to_year=None, make_new_column=False)
Inflates a column of monetary values from one year to another, based on the currency's country.
The provided country can be any economy name or code from the World Bank list of economies.
Note: This method mutates the original DataFrame.
Examples:
>>> import pandas as pd
>>> import janitor.finance
>>> df = pd.DataFrame({"profit":[100.10, 200.20, 300.30, 400.40, 500.50]})
>>> df
profit
0 100.1
1 200.2
2 300.3
3 400.4
4 500.5
>>> df.inflate_currency(
... column_name='profit',
... country='USA',
... currency_year=2015,
... to_year=2018,
... make_new_column=True
... )
profit profit_2018
0 100.1 106.050596
1 200.2 212.101191
2 300.3 318.151787
3 400.4 424.202382
4 500.5 530.252978
Parameters:
Name | Type | Description | Default |
---|---|---|---|
df
|
DataFrame
|
A pandas DataFrame. |
required |
column_name
|
str
|
Name of the column containing monetary values to inflate. |
None
|
country
|
str
|
The country associated with the currency being inflated. May be any economy or code from the World Bank List of economies. |
None
|
currency_year
|
int
|
The currency year to inflate from. The year should be 1960 or later. |
None
|
to_year
|
int
|
The currency year to inflate to. The year should be 1960 or later. |
None
|
make_new_column
|
bool
|
Generates new column for inflated currency if True, otherwise, inflates currency in place. |
False
|
Returns:
Type | Description |
---|---|
DataFrame
|
The DataFrame with inflated currency column. |
Source code in janitor/finance.py
623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 |
|