Как перенаправить вывод из функции печати в фрейм данных pandas? - PullRequest
1 голос
/ 11 июля 2020

У меня есть следующая функция, которая предоставит мне выходные значения с помощью оператора «print». Однако я хочу, чтобы эти значения были сохранены во фрейме данных pandas. Цените вашу помощь.

import pandas as pd

def multilabel3_message(model, scav_df):
    for ind in scav_df.index: 
        doc= (scav_df['park_data'][ind]) 
        doc_list = sentence_tokenizer(doc)
        y_pred = pipeline4.predict(doc_list)
        # Remove double class predictions
        y_pred = list(set(y_pred))
        tags = [dict_classes[i] for i in y_pred]
        # Remove `misc` tag if the list contains other tags as well.
        if len(tags) > 1 and dict_classes[46] in tags:
            del tags[tags.index(dict_classes[46])]  
        print ('{:>30} , {}'.format('['+'] ['.join(tags)+']', doc))

multilabel3_message(pipeline4, scav_df)

, и результат будет таким:

[T32-D] , 'True if location is a user favorite'
                       [T32-D] , 'comma separated list of URLs to images of the location'
                       [T32-D] , 'info on number of spaces in the location, localized string per Lang.'
                       [T32-D] , 'Array of integers as payment method keys accepted at location. Empty array is returned if no data is available or the location is reservable.'
                       [T32-D] , 'Array of integers as payment type keys accepted at location. Empty array is returned if no data is available or the location is reservable.'
                       [T32-D] , 'location ID for the parking location'
                       [T10-D] , 'partner ID'
               [T32-D] [T02-D] , 'type of parking (enum “1” or “2”). 1 will be the value for off-street and 2 will be value for on-street'
                       [T32-D] , 'Coordinates for the parking location'
                       [T32-D] , 'Object containing geometry information of a parking location.'
                       [T32-D] , 'Object containing geometry information of a parking location.'
                       [T32-D] , 'Full pricing details on a single type of parking for a location, time and duration.'
                       [T32-D] , 'total number of ratings for this location'
                       [T32-D] , 'name of location'
                       [T32-D] , 'address of location'

Просто хочу сохранить это напечатанное значение в pandas фрейм данных.

1 Ответ

0 голосов
/ 11 июля 2020

Используйте return вместо print и поместите df= перед вызовом функции

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...