按日期将 ferien-api 和 holidays 库中的值添加到 pandas 数据框

Add values from ferien-api and holidays library to pandas dataframe by date

我想将休假日期插入到我的 pandas 数据框中,但不知道如何... 我的数据框的日期以及来自 ferien-api 和 holidays 库的日期有些问题。这是我的代码:

import pandas as pd
from geopy.geocoders import Nominatim

def add_externals():
    geolocator = Nominatim(user_agent="plantgrid", timeout=3)
    location = geolocator.geocode("Schulweg 23, 26203 Wardenburg")
    federal_state = "NI"
    df = pd.DataFrame(pd.read_csv("Schachtschneider_further.csv", header=0))
    print("----- Adding external data -----")
    df["Auf. Datum"] = pd.to_datetime(df["Auf. Datum"])
    df.index = df["Auf. Datum"].dt.date
    df = WeatherIngest.add_daily_weather_data(df=df, location=location)
    df = CalendarIngest.add_public_holidays(df=df, federal_state=federal_state)
    df = CalendarIngest.add_school_holidays(df=df, federal_state=federal_state)
    df.to_csv("Schachtschneider_externals.csv")

add_public_holidays函数:

import pandas as pd
import holidays

def add_public_holidays(df: pd.DataFrame, federal_state: str):
    federal_state_holidays = holidays.CountryHoliday(country='Germany', prov=federal_state, years=[2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010, 2011, 2012, 2013, 2014, 2015, 2016, 2017, 2018, 2019, 2020])
    if 'public_holiday' not in df.columns:
        df['public_holiday'] = 'no'
    for date in df.index:
        if date in federal_state_holidays:
            df.loc[date, 'public_holiday'] = federal_state_holidays[date]
    
    return df

add_school_holidays:

import pandas as pd
import ferien

def add_school_holidays(df: pd.DataFrame, federal_state: str): 
    for year in range(2001, 2021):
        federal_state_school_holidays = ferien.state_vacations(state_code=federal_state, year=year)
        if 'school_holiday' not in df.columns:
            df['school_holiday'] = 'no'
        for date in df.index:
            print(date)
            for vac in federal_state_school_holidays:
                if vac.start.date() <= date <= vac.end.date():
                    df.at[date, 'school_holiday'] = vac.name
                
    return df

add_daily_weather_data函数与calc_daily_mean_weather_values函数:

import pandas as pd
from datetime import datetime
from geopy.location import Location
from wetterdienst.provider.dwd.observation import DwdObservationRequest, DwdObservationPeriod, DwdObservationResolution, DwdObservationParameter, DwdObservationDataset
from dwdweather import DwdWeather

def calc_daily_mean_weather_values(location: Location) -> pd.Series:
    request = DwdObservationRequest(parameter = DwdObservationDataset.CLIMATE_SUMMARY,
                                         resolution=DwdObservationResolution.DAILY, 
                                         period=DwdObservationPeriod.HISTORICAL, start_date=datetime(2001, 1, 11), 
                                         end_date=datetime(2020, 10, 28), tidy=True, humanize=True, 
                                         si_units=True).filter_by_station_id(station_id=[963])
    df = request.values.all().df
    
    return df


def add_daily_weather_data(df: pd.DataFrame, location: Location):
    daily_mean_weather_values = calc_daily_mean_weather_values(location=location)
    
    temperature = daily_mean_weather_values.loc[daily_mean_weather_values['parameter'] == 'temperature_air_200']
    temperature_values = temperature['value'].to_list()
    temperature_values = [x - 273.15 for x in temperature_values]
    df['mean_temp'] = temperature_values
    
    humidity = daily_mean_weather_values.loc[daily_mean_weather_values['parameter'] == 'humidity']
    humidity_values = humidity['value'].to_list()
    df['mean_humid'] = humidity_values
        
    precipitation_height = daily_mean_weather_values.loc[daily_mean_weather_values['parameter'] == 'precipitation_height']
    precipitation_height_values = precipitation_height['value'].to_list()
    df['mean_prec_height_mm'] = precipitation_height_values
    df['total_prec_height_mm'] = [x * 24 for x in precipitation_height_values]
    
    sunshine_duration = daily_mean_weather_values.loc[daily_mean_weather_values['parameter'] == 'sunshine_duration']
    sunshine_duration_values = sunshine_duration['value'].to_list()
    df['mean_sun_dur_min'] = sunshine_duration_values
    df['total_sun_dur_h'] = [x * 24 / 60 for x in sunshine_duration_values] 
    
    return df

我现在已经试了很长时间了,但还没有得出结论。也许有人已经有类似的项目并且知道如何帮助我。

问题是来自 pandas 数据帧的日期和来自 ferien-apiholidays library 的日期分别来自不同的数据类型并且无法识别彼此,这就是为什么我收到一个包含两个日期/两个索引的数据框 ('Auf. Datum'):

Auf. Datum,Auf. Datum,Acaena,Acantholimon,Acanthus,Acer palmatum,Aceriphyllum,Achillea,Achnatherum,Acinos,Aconitum,Aconogonon,Acorus,Actaea,Adenophora,Adiantum,Adonis,Aegopodium,Aethionema,Agapanthus,Agastache,Agrimonia,Ajania,Ajuga,Akebia,Alcalthaea,Alcea,Alchemilla,Alisma,Alliaria,Allium,Alopecurus,Aloysia,Alstroemeria,Althaea,Alyssum,Amelanchier,Ammophila,Amorpha,Amsonia,Anacyclus,Ananassalbei,Anaphalis,Anchusa,Andropogon,Androsace,Anemone,Anemonopsis,Anethum,Angelica,Anisodontea,Annemona,Antennaria,Anthemis,Anthericum,Anthoxanthum,Anthriscus,Anthyllis,Apfel,Apfelquitte,Aponogeton,Aquilegia,Arabis,Aralia,Arctanthemum,Arctostaphylos,Arenaria,Arisaema,Aristolochia,Armeria,Armoracia,Arnica,Aronia,Arrhenatherum,Artemisia,Arum,Aruncus,Arundo,Asarum,Asclepia,Asparagus,Asperula,Asphodeline,Asphodelus,Asplenium,Aster,Astilbe,Astilboides,Astrantia,Athyrium,Atropa,Aubrieta,Avena,Azolla,Azorella,BLumenzwiebeln,Bacopa,Baerenklau 'White Lips',Baldellia ranunculoides,Ballota,Baptisia,Barbarea,Basilikum,Begonia,Belamcanda chinensis,Berberis,Bergenia,Bergprimel,Berkleya purpurea,Beta,Bigelowia nutallii,Birne,Birnenquitte h,Bistorta,Blechnum,Bletilla,Bluetenschleier,Bluetenwoge,Blumenzwiebel,Blutwurz 'Plenum',Boehmeria sieboldiana,Boltonia,Borago,Bouteloua,Brassica,Briza,Brombeere,Brunnera,Bryonia,Buddleja,Buglossoides,Buphthalmum,Butomus,Buxus,Calamagrostis,Calamintha,Calceolaria,Calendula,Calla,Callitriche,Caltha,Camassia,Campanula,Canna,Capsicum frutescens,Cardamine,Cardiocrinum,Carduncellus,Carex,Carlina,Carpinus,Carum,Caryopteris,Catananche,Centaurea,Centaurium,Centranthus,Cephalaria,Cerastium,Ceratophyllum,Ceratostigma,Ceterach officinarum,Chaenarrhinum,Chamaemelum,Chamomilla recutita,Chasmanthium,Cheilanthes lanosa,Cheiranthus cheiri,Chelidonium,Chelone,Chenopodium,Chiastophyllum,Chionodoxa,Chrypogon gryllos,Chrysanthemum,Cichorium,Cimicifuga,Cirsium,Cistus,Claytonia sibirica,Clematis,Cochlearia officinalis,Codonopsis,Colchicum,Colocasia,Convallaria,Convolvulus,Cordyline,Coreopsis,Coriandrum,Cornus,Coronilla varia,Cortaderia,Cortusa matthioli,Corydalis,Coryllus,Cosmos,Cotoneatser,Cotula,Crambe,Crassula,Crataegus,Crepis biennis,Crinum,Crocosmia,Crocus,Cryptotaenia japonica 'Atropurpurea',Cychorium instibus 'Wegwarte',Cyclamen,Cymbalaria,Cymbopogon,Cynara,Cynoglossum,Cyperus,Cypripedium,Cyrtomium,Cystopteris,Cytisus,Dachgartenstauden,Dactylorhiza,Dahlia,Dalina,Darmera,Datisca cannabina,Daucus,Delosperma,Delphinium,Dendranthema,Deschampsia,Dianthus,Diascia,Dicentra,Dicksonia,Dictamnus,Dierama pulcherimum,Diervilla,Digiplexis,Digitalis,Dionaea,Diplotaxis tenuifolia her,Dipsacus,Disporum flavens,Dodecatheon,Doronicum,Draba,Dracocephalum,Drosera,Dryas,Dryopteris,Duchesnea indica,Echinacea,Echinops,Echium,Edelweiss,Edraianthus graminifolius,Eichhornia,Eleocharis,Elodea,Epilobium,Epimedium,Epipactis,Equisetum,Eragrostis,Eranthis hyemalis,Eremurus,Erigeron,Erinus,Eriocephalus africanus,Eriophorum,Eriophyllum,Erodium,Eryngium,Erysimum,Erythronium,Eucalyptus,Eucomis,Euonymus,Eupatorium,Euphorbia,Exotischer Bluetensaum,Fallopia,Farn,Festuca,Filipendula,Foeniculum,Fontinalis,Forsythia,Fragaria,Francoa sonchifolia varsonchifoliahne Bil,Freiland-Orchidee 'Formosana',Fritillaria,Fruehlingsstauden,Fuchsia,Funkie,Gaillardia,Galanthus nivalis ssp nivaliswiebel,Galega,Galium,Galtonia,Gartenaurikel rot,Gaura,Genista sagittalis,Gentiana,Geranium,Geum,Gillenia,Gladiolus,Glechoma,Globularia,Glyceria,Glycyrrhiza,Goniolimon,Graeser in Sorten,Gratiola officinalis,Gunnera,Gymnocarpium dryopteris,Gynostemma,Gypsophila,Hakonechloa,Halimiocistus,Hamamelis,Haplopappus lyalii,Hauswurz,Havelschwan 'Yellow Satellit',Hedera,Heimischer Bluetensaum,Helenium,Helianthemum,Helianthus,Helichrysum,Helictotrichon,Heliopsis,Helleborus,Helonias bullata,Hemerocallis,Hepatica,Heracium aurantiacum,Herbstanemonen rot,Herbstenzian,Herniaria,Hesperis,Heuchea,Heuchera,Heucherella,Hibiscus,Hieracium,Himbeeren,Hippuris,Hohe,Holcus,Honigsalbei,Horminum,Hosta,Hottonia,Houttuynia,Humulus,Hutchinsia,Hyacinthoides,Hyacinthus multiflorawiebel,Hydrangea,Hydrocharis,Hylomecon,Hypericum,Hyssopus,Hystripatula,Iberis,Ilex,Imperata,Incarvillea,Indigofera,Indocalamus tesselatus,Inula,Ipheion uniflorum,Ipomoea,Iris,Isatis tinctoria,Isolepis cernua,Isotoma,Jasione,Jeffersonia,Johannisbeere,Josta B,Jovibarba,Juglans,Juncus,Kakteen winterhart,Kalimeris,Kamille,Kirengeshoma,Kissenprimel,Kletter-Erdbeere,Knautia,Kniphofia,Knoblaurauke,Koeleria,Kraeuter,Kreuzknabenkraut,Kuklturheidelbeeren i S /,Lageubrieta cultorum blau,Lamium,Lathyrus,Laurus,Lavandula,Lavatera,Ledum,Lemna,Leontopodium,Leonurus,Leptodermis,Leucanth,Leucojum,Leucosceptrum japonicum 'Goldenngel',Levisticum,Lewisia,Leycesteria formosa,Leymus,Liatris,Libertia ixioides 'Goldfinger',Lichtspieler,Ligularia,Ligusticum,Ligustrum,Lilium,Limonium,Linaria,Linum,Lionorus cardiaca,Lippia,Liriope,Lithodora,Lithospermum purpur,Lobelia,Lonicera,Lotos,Lunaria,Lupinen in Sorten Jgw,Lupinen versch Sorten bluehend,Lupinus,Luronium natans,Luzula,Lychnis,Lycium,Lycopus europaeus,Lysichiton,Lysimachia,Lythrum,Macleaya,Maianthemum,Majoran,Malva,Mandragora (Alraune),Margeriten Ester Red,Mariendistel,Mariubium vulgare,Marrubium,Marsilea quadrifolia,Matricaria,Matteuccia,Mazus,Meconopsis,Melica,Melissa,Melittis,Mentha,Menyanthes,Mertensia,Meum,Micromeria,Milium,Millium,Mimulus,Misc Littleebra JGW,Miscanthus,Mitchella repens,Mix-CC mit  Solis im,Molinia,Monarda,Montia,Moorsegge,Morina longifolia,Muehlenbeckia,Muhlenbergia capillaris,Mukdenia,Mukgenia,Musa,Muscari,Myosotis,Myriophyllum,Myrrhis,Myrthis odorata,Narcissus,Narthecium ossifragum,Nasturtium,Nelkenwurz,Nelumbo,Neopaxia,Nepeta,Neuseelaenderflachs,Nierembergia repens,Nitella flexibilis,Nuphar,Nymphaea,Nymphoides,Ocimum,Oenanthe,Oenothera,Omphalodes,Onoclea,Ononis spinosa,Onopordum,Ophiopogon,Ophrys sphegodes incubacea,Opuntia,Orchidee,Orchis,Origano,Ornithogalum umbellatum,Orontium aquaticum,Osmunda,Oxalis,Pachyphragma macrophylla,Pachysandra,Paeonia,Paeonie,Paniculata,Panicum,Papaver,Paradisea liliastrum,Paris quadrifolia,Parnassia palustris,Paronychia kapela ssp serpyllifolia,Parthenium integrifolium,Parthenocissus var engelmannii,Patrinia scabiosifolia,Paulowuia tomentosa,Pelargonium endlicherianum,Peltiphyllum peltatum,Pennisetum,Penstemon,Perovskia,Persicaria,Petasites,Petrorhagia,Petroselinum,Peucedanum,Phalaris,Philadelphus,Phlox,Pholipullus  Maiapfel,Phormium,Phragmites,Phuopsis,Phygelius,Phyla,Phyllitis,Physalis,Physocarpus,Physostegia,Phyteuma,Phytolacca,Pilularia globulifera,Pimpinella,Pinellia ternata,Pistia,Plantago lanceolata,Platycodon,Pleioblastus,Pleione,Poa,Podophyllum,Polemonium,Polygala,Polygonatum,Polygonum,Polypodium,Polystichum,Pontederia,Potamogeton,Potentilla,Pratia,Preslia,Primula,Prizelago,Prizelago alpina 'Icecube',Prizelago alpina sspalpina,Prunella,Prunus l Herbergii,Pseudofumaria alba,Pseudolysimachion,Pseudosasa,Pteridium,Pulmonaria,Pulsatilla,Puschkinia scilloideswiebel,Pycanthemum,Pycnanthemum,Quellmoos lose,Rabdosia longituba,Ramonda,Ranunculus,Raoulia australis,Ratibida,Reseda lutea,Reynoutria,Rhababer The Sutton,Rhabarber,Rhadiola rosea,Rheum,Rhodiola rosea,Rhodohypoxis,Rhodoxis,Rispengras,Robinia,Rodgersia,Romneya,Rosa,Roscoea,Rose,Rosmarin,Rosularia aizoon,Rudbeckia,Rumeabtusofilius,Rumeacetosa,Rumeofficinalis,Rumerugosus,Rumesanguineus,Rumescutataus,Rumescutatus,Rungia,Ruta,Saccharum (Erianthus) ravennae,Sagina,Sagittaria,Salbei,Salicaprea,Salielegantissima /,Salvia,Salvinia,Sambucus,Sanguinaria,Sanguisorba,Santolina,Saponaria,Sarracenia,Saruma henryi,Sasa,Satureja,Saururus,Saxifraga,Scabiosa,Schattentraeumer,Schizachyrium,Schizostylis coccinea,Schleierkraut kriechend,Schoenoplectus,Scilla,Scirpus,Scleranthus uniflorus,Scrophularia macrantha 'Cardinal Red',Scutellaria,Sedoro,Sedum,Seerose rosa  groesseres Exemplar,Seidenmohn aubergine-farbig,Selaginella helvetica,Selinum,Semiaquilegia ecalcarata,Sempervivella,Sempervivium,Sempervivum,Senecio,Serratula tinctoria,Seseli,Sesleria,Setcracea hirsuta 'Swifttale',Sidalcea,Sideritis,Silbersommer,Silberwurz,Silene,Silinum walichianum,Silphium,Silybum,Sinarundinaria   Jumbo (U),Sisyrinchium,Smilacina,Solanum,Soldanella,Solidago,Solidora,Solitaer,Sommerenzian,Sommernachtstraum,Sonnenhut schwarz/dunkel,Sorghastrum,SparMixCC,Sparganium,Spartina,Sphaeralcea ambigua 'Childerley',Sphagnum,Spilanthes 'Peek-A-Boo',Spiraea,Spodiopogon,Sporobolus,Stachelbeere,Stachys,Stauden,Steingartenstauden,Stellaria,Stengelloser Enzian,Stephanandra,Stevia,Stipa,Stokesia,Stratiotes,Stratoides,Strobelianthes,Strobilanthes atropurpureus,Succisa pratensis,Suesskirsche,Suessklee,Symphyandra pendula,Symphytum,Syringa,Tagetes,Tanacetum,Taraxacum pseudoroseum,Taxus,Telekia,Tellima,Telypteris palustris,Teppichsedum,Tetrapanapapyrifera 'Rex',Teucrium,Thalictrum,Thelypteris palustris,Thermopsis,Thymian,Thymus,Tiarella,Topinambour,Townsendia rothrockii,Trachystemon,Tradescantia,Traenendes Herz,Trapa,Tray,Trays,Tricyrtis,Trifolium,Trillium,Trollius,Tropaeolum,Tulipa,Tussilago farfara,Typha,Uncinia,Unicinia 'Rubra',Utricularia,Uvularia,Vaccinium myrtillus,Valeriana,Vancouveria hexandra,Veratrum,Verbascum,Verbena,Vernonia,Veronica,Viburnum,Vinca,Viola,Wahlenbergia albomarginata,Waldsteinia,Wasserhahnenfuss,Weigela,Weinrebe C /,Wisteria sinensis  /,Woodsia,Wulfenia carinthiaca,Yucca,Zantedeschia,Zigadenus elegans,Zitronemelisse gelb/bunt,Zitronenverbene,Zizania,mean_temp,mean_humid,mean_prec_height_mm,total_prec_height_mm,mean_sun_dur_min,total_sun_dur_h,public_holiday,school_holiday
2001-01-12,2001-01-12,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.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0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,-1.0,97.0,0.0,0.0,0.0,0.0,no,no

我通过将每个日期对象更改为 datetime.date.

解决了我的问题
def add_externals():
geolocator = Nominatim(user_agent='plantgrid', timeout=3)
location = geolocator.geocode('Schulweg 23, 26203 Wardenburg')
federal_state = 'NI'
df = pd.DataFrame(pd.read_csv('Schachtschneider_further.csv', header=0)) # , index_col=0
print("----- Adding external data -----")
df['Auf. Datum'] = pd.to_datetime(df['Auf. Datum'])
df['Auf. Datum'] = df['Auf. Datum'].dt.date
df.index = df['Auf. Datum']
df = WeatherIngest.add_daily_weather_data(df=df, location=location)
df = CalendarIngest.add_public_holidays(df=df, federal_state=federal_state)
df = CalendarIngest.add_school_holidays(df=df, federal_state=federal_state)

def add_public_holidays(df: pd.DataFrame, federal_state: str):
    federal_state_holidays = holidays.CountryHoliday(country='Germany', prov=federal_state, years=[2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010, 2011, 2012, 2013, 2014, 2015, 2016, 2017, 2018, 2019, 2020])
    if 'public_holiday' not in df.columns:
        df['public_holiday'] = 'no'
    for date in df.index:
        if date in federal_state_holidays:
            df.at[date, 'public_holiday'] = federal_state_holidays[date]
    
    return df


def add_school_holidays(df: pd.DataFrame, federal_state: str): # , date: datetime.date
    for year in range(2001, 2021):
        federal_state_school_holidays = ferien.state_vacations(state_code=federal_state, year=year)
        if 'school_holiday' not in df.columns:
            df['school_holiday'] = 'no'
        index = df['Auf. Datum']
        for date in index:
            for vac in federal_state_school_holidays:
                if vac.start.date() <= date <= vac.end.date():
                    df.at[date, 'school_holiday'] = vac.name
                
    return df