Pandas convert dataframe to array of tuples

Pandas convert dataframe to array of tuples

Asked on December 21, 2018 in Pandas.
Add Comment


  • 3 Answer(s)

    Try the below code for the best solution:

    subset = data_set[['data_date', 'data_1', 'data_2']]
    tuples = [tuple(x) for x in subset.values]
    
    Answered on December 21, 2018.
    Add Comment

    The below code is more common:

    [tuple(x) for x in data_set.to_records(index=False)]
    
    
    Answered on December 21, 2018.
    Add Comment

    Refer to the document before proceeding:

    The below code will output as namedtuples.

    list(data_set.itertuples(index=False))
    
    Answered on December 21, 2018.
    Add Comment


  • Your Answer

    By posting your answer, you agree to the privacy policy and terms of service.