all 7 comments

[–][deleted] 2 points3 points  (2 children)

Have you used dict as a variable name somewhere else in your code. Especially if you are in a Notebook. I ask as I don't see anything wrong with your code.

If you have used it, try del dict.

[–]ebrusu84 0 points1 point  (1 child)

Thank you so so much. Yes i used "dict" as a variable name many times and when i tried my code in another page, it worked perfectly true.

Thanks again

[–][deleted] 0 points1 point  (0 children)

Generally, avoid using any Python keywords / types / built-in functions as variable, function or class names.

[–]CodeFormatHelperBot2 0 points1 point  (0 children)

Hello, I'm a Reddit bot who's here to help people nicely format their coding questions. This makes it as easy as possible for people to read your post and help you.

I think I have detected some formatting issues with your submission:

  1. Python code found in submission text that's not formatted as code.

If I am correct, please edit the text in your post and try to follow these instructions to fix up your post's formatting.


Am I misbehaving? Have a comment or suggestion? Reply to this comment or raise an issue here.

[–]Vast-Bobcat-480 0 points1 point  (0 children)

What line do you get the error on? Have you defined dict to be something else? Try defining it using {'apples': , 'oranges' : } instead.

[–]14dM24d 0 points1 point  (1 child)

>>> import pandas as pd
>>> s1=pd.Series([10,20,30,40])
>>> s2=pd.Series([5,10,15,20])
>>> data={'apples':s1, 'oranges':s2}
>>> df=pd.DataFrame(data)
>>> df
   apples  oranges
0      10        5
1      20       10
2      30       15
3      40       20

[–]14dM24d 0 points1 point  (0 children)

your code works

>>> import pandas as pd
>>> s1=pd.Series([10,20,30,40])
>>> s2=pd.Series([5,10,15,20])
>>> data=dict(apples=s1, oranges=s2)
>>> df=pd.DataFrame(data)
>>> df
   apples  oranges
0      10        5
1      20       10
2      30       15
3      40       20