0

I am trying to make a new dataframe of 2 columns. First column is id and second column is predictions. I want to create a dataframe with first column id which is taken from testdata and predictions is an array of 0's and 1's. Column names should be id and predictions.

Sample data:

enter image description here

My new create dataframe should be like this:

Expected output:

id      predictions
3242        0
3246        1
7655        1
1324        0
4643        1

I tried following code but I am getting some error please check screenshot:

enter image description here

stone rock
  • 1,923
  • 9
  • 43
  • 72

2 Answers2

2

I believe need if lenght of testdata is same as predictions:

Test it:

print (len(testdata))

print (len(predictions))

df = pd.DataFrame({'id':testdata['id'], 'predictions':predictions})
jezrael
  • 822,522
  • 95
  • 1,334
  • 1,252
1

If the length of the arrays are equal

df = pd.DataFrame({'id':testdata['id']})
df["Predictions"] = predictions
Vishnu Kiran
  • 620
  • 7
  • 15