Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

append dictionary to data frame

I have a function, which returns a dictionary like this:

{'truth': 185.179993, 'day1': 197.22307753038834, 'day2': 197.26118010160317, 'day3': 197.19846975345905, 'day4': 197.1490578795196, 'day5': 197.37179265011116} 

I am trying to append this dictionary to a dataframe like so:

output = pd.DataFrame() output.append(dictionary, ignore_index=True) print(output.head()) 

Unfortunately, the printing of the dataframe results in an empty dataframe. Any ideas?

like image 703
cs0815 Avatar asked Aug 09 '18 19:08

cs0815


People also ask

Can you append a dictionary to a DataFrame?

Append list of dictionary and series to a existing Pandas DataFrame in Python. In this article, we will discuss how values from a list of dictionaries or Pandas Series can be appended to an already existing pandas dataframe. For this purpose append() function of pandas, the module is sufficient.

How do you put a dictionary in a data frame?

You can convert a dictionary to Pandas Dataframe using df = pd. DataFrame. from_dict(my_dict) statement.

How do you add a dictionary row to a DataFrame?

Append Dict as Row to DataFrame You can create a DataFrame and append a new row to this DataFrame from dict, first create a Python Dictionary and use append() function, this method is required to pass ignore_index=True in order to append dict as a row to DataFrame, not using this will get you an error.

How do you append to a data frame?

Dataframe append syntaxYou type the name of the first dataframe, and then . append() to call the method. Then inside the parenthesis, you type the name of the second dataframe, which you want to append to the end of the first.


1 Answers

You don't assign the value to the result.

output = pd.DataFrame() output = output.append(dictionary, ignore_index=True) print(output.head()) 
like image 56
alex Avatar answered Sep 21 '22 05:09

alex