While reviewing code from a colleague, I came across a -> pd.DataFrame
in a Python function. I discovered that this indicates that the function is expected to return a pandas DataFrame.
Learning something new everyday
I like learning something new everyday and today it was these type of hints for Python function. I am sure I saw them before, but might have been "too focus" on something else to even wonder what they are.
So, how does it work?
- Create a function, let's call it create_dataframe
- Before the
:
on the first row,-> pd.DataFrame
- Voila, you got it
In other words it would look like this:
import pandas as pd import pandas_gbq as pbq def create_dataframe() -> pd.DataFrame: query = "SELECT * FROM your_bq_table" return pbq.read_gbq(query)
In this example I used the pandas_gbq
to query a Big Query data base in SQL