Je devrais changer d'étiquette si au moins une des colonnes de la trame de données contient l'un des mots suivants:
import pandas as pd
import numpy as np
df = pd.DataFrame(np.array([['Ferrari was hit by a radio communication blackout' , 'Scuderia Ferrari trying a double pit stop', ' If Ferrari takes nothing else away from the 2019 season, it must learn from its mistakes across the season'], ['We may use the following original news sources for stories', 'Sebastian Vettel insisted he trusts in Ferrari', 'During the recent Grand Prix of Italy, the Scuderia Ferrari team managed to execute one of the fastest pit stops ever performed during a Formula 1 race']]),
columns=['Text1', 'Short','Data'])
3 Réponses :
Vous pouvez le faire en effectuant un fichier de données de liste, puis de l'ajouter à votre image de données principale ici est le code.
0 Ferrari was hit by a radio communication blackout Scuderia Ferrari trying a double pit stop If Ferrari takes nothing else away from the 2... pit 1 We may use the following original news sources... Sebastian Vettel insisted he trusts in Ferrari During the recent Grand Prix of Italy, the Scu... stop
Cela ne répond pas à la question de l'OP, examine la réponse avant de poster.
Vous devriez vérifier cette Stackoverflow.com / Questions / 3271478 / ... Upvote s'il vous plaît.
Essayez ceci: espère que cela aide !!! p> p> p>
L'utilisation de la fonction personnalisée avec la boucle est plus lente que d'utiliser des fonctions intégrées ... Cette approche coupe le temps d'exécution de 50%
J'utilise ma propre fonction (chk_word) pour vérifier et écrire 'check_words'.
def chk_word(row):
for c in check_words:
if row.str.contains(c).any():
return c
df['Label'] = df.apply(chk_word, axis=1)
df
Text1 Short Data Label
0 Ferrari was hit by a radio communication blackout Scuderia Ferrari trying a double pit stop If Ferrari takes nothing else away from the 2... pit
1 We may use the following original news sources... Sebastian Vettel insisted he trusts in Ferrari During the recent Grand Prix of Italy, the Scu... pit
Quelle sera la sortie attendue pour l'entrée donnée ci-dessus?