Skip to content

Overview

read_historical_trips(start_date, city, end_date=None)

Read historical trips within given range of dates for a city.

Parameters:

Name Type Description Default
start_date str

start date for the data in %Y-%m-%d format

required
city str

city to read data from

required
end_date Union[str, None]

end date in the same format. Defaults to last date available

None

Returns:

Type Description
pd.DataFrame

Historical trip DataFrame for the date range provided.

Examples:

Read trips from Jan 1st 2021 until Feb 1st 2021 in Chicago

import lyft_bikes

df = lyft_bikes.read_historical_trips(
    start_date="2021-01-01",
    end_date="2021-02-01",
    city="Chicago",
)
Source code in lyft_bikes/__init__.py
def read_historical_trips(
    start_date: str,
    city: str,
    end_date: Union[str, None] = None,
) -> pd.DataFrame:
    """Read historical trips within given range of dates for a city.

    Args:
        start_date: start date for the data in %Y-%m-%d format
        city: city to read data from
        end_date: end date in the same format. Defaults to last date available

    Returns:
        Historical trip DataFrame for the date range provided.

    Examples:
        Read trips from Jan 1st 2021 until Feb 1st 2021 in Chicago

        ```python
        import lyft_bikes

        df = lyft_bikes.read_historical_trips(
            start_date="2021-01-01",
            end_date="2021-02-01",
            city="Chicago",
        )
        ```


    """
    if city not in CITY_DOWNLOADERS:
        raise ValueError(
            f"City {city} is not supported. Supported cities are {CITY_DOWNLOADERS.keys()}"
        )

    dates = CITY_DATES.get(city, bike_dates.DefaultDates)()

    downloader = CITY_DOWNLOADERS[city]()
    trips = HistoricalTrips(
        dates=dates,
        downloader=downloader,
    )
    return trips.read(start_date=start_date, end_date=end_date)

read_live_bikes(city)

Read currently available bikes and scooters.

Parameters:

Name Type Description Default
city str

city to read data from

required

Returns:

Type Description
pd.DataFrame

DataFrame with the current status of bikes and scooters.

Source code in lyft_bikes/__init__.py
@chicago_only_error
def read_live_bikes(city: str) -> pd.DataFrame:
    """Read currently available bikes and scooters.

    Args:
        city: city to read data from

    Returns:
        DataFrame with the current status of bikes and scooters.

    """
    live = Bikes()
    return live.read()

read_stations(city)

Read information and status for each station.

Parameters:

Name Type Description Default
city str

city to read data from

required

Returns:

Type Description
pd.DataFrame

DataFrame with the stations information and status.

Source code in lyft_bikes/__init__.py
@chicago_only_error
def read_stations(city: str) -> pd.DataFrame:
    """Read information and status for each station.

    Args:
        city: city to read data from

    Returns:
        DataFrame with the stations information and status.

    """
    station_info = StationInfo()
    station_status = StationStatus()

    return pd.merge(
        station_status.read(),
        station_info.read(),
        how="inner",
        on=["station_id", "legacy_id"],
    )