I was trying to create and display a pandas data frame in IBM Watson Notebook. I have 4 List of data and I tried to create a data frame with the help of a Dictionary.

The Python Code

dict = {'Trip': tripNoList,'A_MAX': actualMaxList, 'A_MIN': actualMinList, 'LR_Pred_MAX':predictionLRMax, 'AR_Pred_MAX':predictionARMax} 
dfexport1 = pd.DataFrame(dict) 
display(dfexport1.head())

But the result Shows disorderly arranged data frame,

<table border="1" class="dataframe">
  <thead>
    <tr style="text-align: right;">
      <th></th>
      <th>AR_Pred_MAX</th>
      <th>A_MAX</th>
      <th>A_MIN</th>
      <th>LR_Pred_MAX</th>
      <th>Trip</th>
    </tr>
  </thead>
  <tbody>
    <tr>
      <th>0</th>
      <td></td>
      <td>1.174</td>
      <td>1.130</td>
      <td></td>
      <td>1</td>
    </tr>
    <tr>
      <th>1</th>
      <td></td>
      <td>1.136</td>
      <td>0.947</td>
      <td></td>
      <td>2</td>
    </tr>
    <tr>
      <th>2</th>
      <td></td>
      <td>1.081</td>
      <td>1.029</td>
      <td></td>
      <td>3</td>
    </tr>
    <tr>
      <th>3</th>
      <td></td>
      <td>1.029</td>
      <td>0.949</td>
      <td></td>
      <td>4</td>
    </tr>
    <tr>
      <th>4</th>
      <td></td>
      <td>0.955</td>
      <td>0.829</td>
      <td></td>
      <td>5</td>
    </tr>
  </tbody>
</table>

But it works fine in Jupyter notebook. I have tried

  • display ()
  • print()
  • display(HTML())

But Nothing gave me the correct output. can anyone help to solve this issue?

1 Answers

2
Simon O'Doherty On Best Solutions

You need to specify the sequence of the columns in pandas.

Example:

df = pd.DataFrame(data, columns=[‘col1’, ‘col2’])