Apr-14-2018, 01:52 AM
Hello,
this is my first post about Python, and also this is my first post in English. So... thank you for your patience :)... And sorry for my low english level, I'm practicing to improve.
I want to build a pandas Dataframe but the rows info are coming to me one by one (in a for loop), in form of a dictionary (or json).
In each iteration I receive a dictionary where the keys refer to the columns, and the values are the rows values. For example:
1st Iteration I receive:
d_val = {'key1': 1.1, 'key2':2.2, 'key3':3.3}
And I want to build a dataframe (called df), where column names will be d_val.keys(), and the first row values will be d_val.values()
2nd Iteration I receive:
{'key1': 4.4, 'key2':5.5, 'key3': 6.6}
And I want to append the values to a new row in the datframe.
Example outcome wanted:
key1---key2----key3
1.1-----2.2------3.3
4.4-----5.5------6.6
And each new iteration, will make a new row append. I will be sure that in each iteration the dict keys are the same.
I try to create a empty dataframe or a dataframe with only de columns values, and then use the DataFrame.append method... but never works. I'm lost, because I think that It will not be so difficult.
I hope that I have explained well.
Thanks
this is my first post about Python, and also this is my first post in English. So... thank you for your patience :)... And sorry for my low english level, I'm practicing to improve.
I want to build a pandas Dataframe but the rows info are coming to me one by one (in a for loop), in form of a dictionary (or json).
In each iteration I receive a dictionary where the keys refer to the columns, and the values are the rows values. For example:
1st Iteration I receive:
d_val = {'key1': 1.1, 'key2':2.2, 'key3':3.3}
And I want to build a dataframe (called df), where column names will be d_val.keys(), and the first row values will be d_val.values()
2nd Iteration I receive:
{'key1': 4.4, 'key2':5.5, 'key3': 6.6}
And I want to append the values to a new row in the datframe.
Example outcome wanted:
key1---key2----key3
1.1-----2.2------3.3
4.4-----5.5------6.6
And each new iteration, will make a new row append. I will be sure that in each iteration the dict keys are the same.
I try to create a empty dataframe or a dataframe with only de columns values, and then use the DataFrame.append method... but never works. I'm lost, because I think that It will not be so difficult.
I hope that I have explained well.
Thanks