in Education by
I have a Python dictionary like the following: {u'2012-06-08': 388, u'2012-06-09': 388, u'2012-06-10': 388, u'2012-06-11': 389, u'2012-06-12': 389, u'2012-06-13': 389, u'2012-06-14': 389} The keys are Unicode dates and the values are integers. I would like to convert this into a pandas data frame by having the dates and their corresponding values as two separate columns. Example: col1: Dates col2: DateValue (the dates are still Unicode and date values are still integers) Date Date Value 0 2012-07-01 391 1 2012-07-02 392 2 2012-07-03 392 3 2012-07-04 392 . … ... Any help in this direction would be much appreciated. I am unable to find resources on the pandas docs to help me with this. I know one solution might be to convert each key-value pair in this dict, into a dict so the entire structure becomes a dict of dicts, and then we can add each row individually to the data frame. But I want to know if there is an easier way and a more direct way to do this. So far I have tried converting the dict into a series object but this doesn't seem to maintain the relationship between the columns: s = Series(my_dict,index=my_dict.keys()) Select the correct answer from above options

1 Answer

0 votes
by
 
Best answer
You can simply use: pandas.DataFrame.from_dict This function takes a dictionary as input to convert into a data frame. For Example: >>> data = {'col_1': [3, 2, 1, 0], 'col_2': ['a', 'b', 'c', 'd']} >>> pd.DataFrame.from_dict(data) col_1 col_2 0 3 a 1 2 b 2 1 c 3 0 d Hope this answer helps.

Related questions

0 votes
    Suppose I have a Tensorflow tensor. How do I get the dimensions (shape) of the tensor as integer values? I ... 'Dimension' instead. Select the correct answer from above options...
asked Feb 8, 2022 in Education by JackTerrance
0 votes
    I am trying to decompose a 3D matrix using python library scikit-tensor. I managed to decompose my Tensor ... the decomposed matrices? Select the correct answer from above options...
asked Feb 1, 2022 in Education by JackTerrance
0 votes
    I am new to TensorFlow. While I am reading the existing documentation, I found the term tensor really confusing. ... types of tensors? Select the correct answer from above options...
asked Jan 29, 2022 in Education by JackTerrance
0 votes
    I have a 20 x 4000 dataframe in python using pandas. Two of these columns are named Year and quarter. I'd ... anyone help with that? Select the correct answer from above options...
asked Jan 28, 2022 in Education by JackTerrance
0 votes
    I recently started finding out deep learning & machine learning techniques, and I started sorting out frameworks ... machine learning. Select the correct answer from above options...
asked Jan 22, 2022 in Education by JackTerrance
0 votes
    I have worked all the tutorials and searched for "load csv tensorflow" but just can't get the logic of it all. ... and test the net. Select the correct answer from above options...
asked Feb 1, 2022 in Education by JackTerrance
0 votes
    I'm starting with input data like this df1 = pandas.DataFrame( { "Name" : ["Alice", "Bob", "Mallory", ... Any hints would be welcome. Select the correct answer from above options...
asked Jan 28, 2022 in Education by JackTerrance
0 votes
    I am trying to understand the role of the Flatten function in Keras. Below is my code, which is a simple two ... flatten it? Thanks! Select the correct answer from above options...
asked Feb 8, 2022 in Education by JackTerrance
0 votes
    I'm wondering how to calculate precision and recall measures for multiclass multilabel classification, i.e. classification ... labels? Select the correct answer from above options...
asked Jan 31, 2022 in Education by JackTerrance
0 votes
    I'm creating a very basic AI with Tensorflow, and am using the code from the official docs/tutorial. Here's my ... Tensorflow 1.13.1. Select the correct answer from above options...
asked Jan 28, 2022 in Education by JackTerrance
0 votes
    I was looking at the docs of TensorFlow about tf.nn.conv2d here. But I can't understand what it does or ... it raised the question. Select the correct answer from above options...
asked Jan 27, 2022 in Education by JackTerrance
0 votes
    What is the role of Flatten in Keras. I am executing the code below and it's a two layered network. The ... output is already flat? Select the correct answer from above options...
asked Jan 25, 2022 in Education by JackTerrance
0 votes
    Is Tensorflow similar to scikit learn's one hot encoder for processing of categorical data? Does using placeholder of ... very easy. Select the correct answer from above options...
asked Jan 22, 2022 in Education by JackTerrance
0 votes
    I started Tensorflow some days back and I understand that it is a visualization tool but is there any way to ... remote Ubuntu machine? Select the correct answer from above options...
asked Jan 22, 2022 in Education by JackTerrance
0 votes
    Currently, I have Keras with TensorFlow and CUDA at the backend. But, I want to force Keras to use the ... are accessible via Keras. Select the correct answer from above options...
asked Jan 22, 2022 in Education by JackTerrance
...