Ich habe ein Wörterbuch von Datenrahmen:
two_season_bucket_suffixes = {'two_season_bucket_year1_racer_bio':two_season_bucket_year1_racer_bio,
'two_season_bucket_year1_spring_rate':two_season_bucket_year1_spring_rate,
'two_season_bucket_year1_neaps_rate':two_season_bucket_year1_neaps_rate,
'two_season_bucket_year1_spring_raw':two_season_bucket_year1_spring_raw,
'two_season_bucket_year1_neap_raw':two_season_bucket_year1_neap_raw,
'two_season_bucket_year1_opposing_team':two_season_bucket_year1_opposing_team,
'two_season_bucket_year1_opposing_team_distribution':two_season_bucket_year1_opposing_team_distribution,
'two_season_bucket_year1_stern_score':two_season_bucket_year1_stern_score,
'two_season_bucket_year1_bow_score':two_season_bucket_year1_bow_score,
'two_season_bucket_year1_team_score':two_season_bucket_year1_team_score,
'two_season_bucket_year2_racer_bio':two_season_bucket_year2_racer_bio,
'two_season_bucket_year2_spring_rate':two_season_bucket_year2_spring_rate,
'two_season_bucket_year2_neaps_rate':two_season_bucket_year2_neaps_rate,
'two_season_bucket_year2_spring_raw':two_season_bucket_year2_spring_raw,
'two_season_bucket_year2_neap_raw':two_season_bucket_year2_neap_raw,
'two_season_bucket_year2_opposing_team':two_season_bucket_year2_opposing_team,
'two_season_bucket_year2_opposing_team_distribution':two_season_bucket_year2_opposing_team_distribution,
'two_season_bucket_year2_stern_score':two_season_bucket_year2_stern_score,
'two_season_bucket_year2_bow_score':two_season_bucket_year2_bow_score,
'two_season_bucket_year2_team_score':two_season_bucket_year2_team_score}
Sie haben alle unterschiedliche Spalten, aber alle haben mindestens eine Spalte, die mit dem Wort "Vorhersage" beginnt.
Ich möchte aus jeder Spalte, die mit 'Vorhersage' beginnt, einen neuen Datenrahmen erstellen:
two_season_bucket_prediction= pd.DataFrame()
counter = 0
for key, val in two_season_bucket_suffixes.items():
if counter == 0:
two_season_bucket_prediction= val[val.columns[pd.Series(val.columns).str.startswith('prediction')]]
else:
two_season_bucket_prediction= two_season_bucket_prediction.join(val[val.columns[pd.Series(val.columns).str.startswith('prediction')]])
counter += 1
Jedes Mal, wenn ich am Ende einen Datenrahmen mit einer Spalte namens 'Vorhersage' habe, obwohl ich sicher bin, dass keine Spalte nur Vorhersage heißt
Sie erhöhen den Zähler, wo Sie nie erreichen:
two_season_bucket_prediction= pd.DataFrame()
counter = 0
for key, val in two_season_bucket_suffixes.items():
if counter == 0:
two_season_bucket_prediction= val[val.columns[pd.Series(val.columns).str.startswith('prediction')]]
else:
two_season_bucket_prediction= two_season_bucket_prediction.join(val[val.columns[pd.Series(val.columns).str.startswith('prediction')]])
counter += 1
Dieser Artikel stammt aus dem Internet. Bitte geben Sie beim Nachdruck die Quelle an.
Bei Verstößen wenden Sie sich bitte [email protected] Löschen.
Lass mich ein paar Worte sagen