There are elements of series type. I want to convert these elements into dataframes. However, I cannot do it because of the dictionaries and lists in it. How can I return null for non-null fields and write the non-blank answers to the dataframe?enter image description here
CodePudding user response:
You can use the "to_frame" function to convert the series into a dataframe:
s = pd.Series(["a", "b", "c"],
name="letters")
df = s.to_frame()
CodePudding user response:
If you want a result like in the image for the two series you provided, you can do something like this:
s1 = {'q1':'apple','q2':'12','q4':'banana','q5':'How are you?'}
s2 = {'q1': 'kiwi','q3':'very good','q5':'Wht?'}
df = pd.DataFrame([s1,s2])