Skip to content
This repository has been archived by the owner on May 20, 2021. It is now read-only.

Add a to_frame() method to forecast class #51

Open
dzimmanck opened this issue Feb 10, 2020 · 2 comments
Open

Add a to_frame() method to forecast class #51

dzimmanck opened this issue Feb 10, 2020 · 2 comments
Assignees
Labels
enhancement New feature or request

Comments

@dzimmanck
Copy link

dzimmanck commented Feb 10, 2020

Is your feature request related to a problem? Please describe.
Many libraries that expect weather data as an input use pandas dataframes as the standard data object (PVLib for example). Also, being able to return a pandas dataframe will make it easier to print, plot, and process data returned from darksky.

Describe the solution you'd like
A method called "to_frame()" which returns a DatetimeIndex'd dataframe of weather data.

weather = darksky.get_time_machine_forecast(...)
hourly_forecast_dataframe = weather.hourly.to_frame()

# print the start of the forecast
print(hourly_forecast_dataframe.head())

# plot the temperature
hourly_forecast_dataframe.plot(y='temperature')

Describe alternatives you've considered
Currently I use a function which accepts a forecast as an argument and returns a dataframe. This works just fine, but a built-in method would be nice."

@dzimmanck
Copy link
Author

For reference, here is the function I use.

import pandas as pd


def darksky_forecast_to_dataframe(forecast):
    """Convert darksky forecast data list to a dataframe

    Keyword arguments:
    forecast -- list of daksky forecast items

    Returns:
    df -- DatetimeIndexed pandas dataframe of the forecast data
    """

    # convert list of forecast items to list of dictionaries
    data = [entry.__dict__ for entry in forecast]

    # make the dataframe
    df = pd.DataFrame(data)

    # use time as the index
    df.set_index('time', inplace=True)

    return df

@Detrous Detrous self-assigned this Feb 11, 2020
@Detrous Detrous added the enhancement New feature or request label Feb 11, 2020
@Detrous
Copy link
Owner

Detrous commented Feb 11, 2020

Hi @dzimmanck
Pandas are a heavy requirements. I don’t think it will be needed for just one small function.
I will think what can I do

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants