0

I have an empty existing dataframe with columns

In[337]: df_short_interests.columns
Out[337]: 
Index(['Settlement Date', 'Short Interest', 'Avg Daily Share Volume',
       'Days To Cover'],
      dtype='object')

I have a list below which I would like to add as a row to the dataframe.

row_data = []
row_data.append('2/15/2019')
row_data.append('39,903,215')
row_data.append('26,937,971')
row_data.append('1.481300')

I tried to add the list with the below code and I got warning and the list get added as a column instead.

In[334]:df_short_interests.append(row_data, ignore_index=True)
C:\Users\user\Anaconda3\lib\site-packages\pandas\core\indexes\api.py:107: RuntimeWarning: '<' not supported between instances of 'str' and 'int', sort order is undefined for incomparable objects
  result = result.union(other)
Out[334]: 
   Settlement Date  Short Interest     ...      Days To Cover           0
0              NaN             NaN     ...                NaN   2/15/2019
1              NaN             NaN     ...                NaN  39,903,215
2              NaN             NaN     ...                NaN  26,937,971
3              NaN             NaN     ...                NaN    1.481300

How can I add the list a row instead of a column?

Thank you.

1 Answer 1

2

Append is for adding another dataframe rows to a dataframe. So if you first would create a new dataframe, it would work:

df2 = pd.DataFrame([row_data], columns=['Settlement Date', 
                                           'Short Interest', 
                                           'Avg Daily Share Volume',
                                           'Days To Cover'])

df_short_interests = df_short_interests.append(df2)
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.