• Register
0 votes
18 views

Problem:

I was trying to put some data of my workers in a data frame. I was trying to add their data in an existing Data frame. So I wrote this code:
import pandas as panda 
  

data = 'Name': ['Sam', 'Prince', 'Goragno', 'Abraham'], 
        'Qualification': ['Msc', 'Bsc', 'Msc', 'M.Phil'] 
  

df = panda.DataFrame(data) 
  

address = ['Vancuver', 'New Orland', 'Olulu', 'Gorgia'] 
  

df['Address'] = address 
  

df 

 

But when I run this program it shows:

  File "workers.py", line 4
    data = 'Name': ['Sam', 'Prince', 'Goragno', 'Abraham'], 
                 ^
SyntaxError: invalid syntax

I am newbee please help me to solve this and please explain to me why am I getting this type of errors?

10 7 2
6,050 points

2 Answers

1 vote

Answer:

The main reason you are getting this error because you did not put your data in a list so you should use 

{}

and open and a closing bracket for this.

And write your code as:

import pandas as panda 
  

data = {'Name': ['Sam', 'Prince', 'Goragno', 'Abraham'], 
        'Qualification': ['Msc', 'Bsc', 'Msc', 'M.Phil']} 
  

df = panda.DataFrame(data) 
  

address = ['Vancuver', 'New Orland', 'Olulu', 'Gorgia'] 
  

df['Address'] = address 
  

df 

Hope this may help you. Happy Coding.

11 6 4
34,930 points
1 vote

Solution:

Pro Tip: When you are getting an error or warning from the Python interpreter you should read the message carefully. The compiler or interpreter always gives a hint of our mistakes. Anyway, in your case, you are getting a SyntaxError because you’ve defined a dictionary with some mixed data. In python, a dictionary starts with a curly brace and ends with the same. For example:

dict = {'Name': 'Zara', 'Age': 7, 'Class': 'First'}

Now, have a close look at your defined dictionary. You missed the curly braces. You should have written it this way:

data = {'Name': ['Sam', 'Prince', 'Goragno', 'Abraham'], 'Qualification': ['Msc', 'Bsc', 'Msc', 'M.Phil']}

The dictionary looks good now. Should solve the error. Good day!

13 9 6
94,240 points

Related questions

0 votes
1 answer 7 views
7 views
Problems I am trying to update selected datetime64 values in a pandas data frame using the loc method to select rows satisfying a condition. However, instead of assigning the new date-time value it results in NaT. Here is a simplification of my code that shows the problem: ... as the second element in the new_date column. Any ideas on how this should be done or why this is not working as intended?
asked Sep 15 Marivoke 530 points
0 votes
1 answer 1K views
1K views
I am trying to create a rating data frame for some football teams. To rate the teams I am using elo rating system : https://en.wikipedia.org/wiki/Elo_rating_system My data frame consists of pre-match ratings of home and away teams and it gets updated after every match. My data ... of size 1 to a python scalar Can any one help me to find what the problem really is and help me to solve the problem.
asked Mar 10 LizzyM 6.1k points
0 votes
0 answers 8 views
8 views
I have a dataframe of almost 120000 records as follows. Also I have a mongoDB collection which looks exacly same as below dataframe ItemID ParentID ItemRating ItemPrice Qty A1 ItemA1 0 12 100 A2 ItemA2 0 15 200 B1 ItemB1 0 20 300 B2 ItemB2 0 25 400 B3 ItemB3 0 30 ... PyMongo update_many method by setting upsert=true. but I am not sure how can I do that ? how should I write my filter condition ?
asked Sep 13 NguyenTram 1k points
0 votes
1 answer 176 views
176 views
Problem: I have only fundamental knowledge related to python, pandas and dataframe.I have tried to write the below code: df = pd.DataFrame(np.random.rand(12,2), columns=['Apples', 'Oranges'] ) df['Categories'] = pd.Series(list('AAAABBBBCCCC')) pd.options.display. ... I will be more than glad to get more ideas on the above error regarding why it is occurring and also how to fix this error?
asked Aug 24 Raphael Pacheco 4.9k points
1 vote
1 answer 11 views
11 views
Problem: Hello all, I’ve just completed learning basic python. You may treat me as an intermediate-level python developer though I know learning has no limit in the programming field. Recently, I started learning data analysis using python pandas. Therefore, I am ... and share me the procdure to achieve this? Thanks a lot for reading my problem attentively and your reply to this thread.
asked Jul 5 adamSw 11.3k points