0

I'm trying to insert multiple values in a single cell of pandas data frame using the below code.

Importing the libraries
import pandas as pd
import numpy as np

#Declaring the list
lst = ['accuracy score: 0.550', 'accuracy score: 0.700', 'accuracy score: 0.730', 'accuracy score: 0.730']
fold = ['10']

#Convert the list to pandas dataframe
df = pd.DataFrame(list(zip(lst,fold)),columns =['Accuracy','Folds'])
df.head()

However, when I execute the above code, it returns the df as below :

    |       Accuracy        |  Folds |
    +-----------------------+--------+
    |accuracy score: 0.550  |  10    |
    +-----------------------+--------+

But I want to have the df that looks like below where in the accuracy values are stored under a single cell in pandas dataframe:

Table

So, how can I store the 4 values under a single row using pandas dataframe ?

1 Answer 1

1

You can use a list object for accuracy:

lst = [['accuracy score: 0.550', 'accuracy score: 0.700', 'accuracy score: 0.730', 'accuracy score: 0.730']]
fold = ['10']

#Convert the list to pandas dataframe
df = pd.DataFrame(list(zip(lst,fold)),columns =['Accuracy','Folds'])
df.head()

Result:

Accuracy Folds
['accuracy score: 0.550', 10
'accuracy score: 0.700',
'accuracy score: 0.730',
'accuracy score: 0.730']
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.