Python Forum
Create new column in new created table
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Create new column in new created table
#1
Hi, can anyone assist how to add new column for a new table?

Im very new in using python and this is my first cry for help.

I have 2 tables.
Table 1 contain lists of item with it's manufacturing year and it's types.
Table 2 contains rates for each manufacturing years (from 2005 to 2019) and for different types of item.

How can I create a new table where I can list all the items that match its rates in Table 2 (new column)by looking at the 2 conditions. Below is my code only for 2005. When I run the Python it return IndentationError: expected an indented block

def df(s):
#mfg year 2005
    if (s['mfg_year'] == "2005"):
    if (s['Type'] == "A"):
     
        print (123)     #this is the rate for item with type A manufactured in 2005
    elif (s['Type'] == "B"):
       
        print (0).      #this is the rate for item with type B manufactured in 2005
        else :
            return 0
Reply
#2
it expects indented block after line #3
If you can't explain it to a six year old, you don't understand it yourself, Albert Einstein
How to Ask Questions The Smart Way: link and another link
Create MCV example
Debug small programs

Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  How to create a table with different sizes of columns in MS word pepe 8 1,417 Dec-08-2023, 07:31 PM
Last Post: Pedroski55
  Find a string from a column of one table in another table visedwings049 8 1,085 Sep-07-2023, 03:22 PM
Last Post: deanhystad
  create new column based on condition arvin 12 2,133 Dec-13-2022, 04:53 PM
Last Post: jefsummers
  Python create a spreadsheet with column and row header ouruslife 4 1,552 Jul-09-2022, 11:01 AM
Last Post: Pedroski55
  Insert into SQL Table only when Table is First Created? Extra 4 1,409 Jun-28-2022, 07:50 AM
Last Post: Pedroski55
  group by create pivot table python dawid294 1 1,258 Jun-22-2022, 06:13 PM
Last Post: Larz60+
  Cannot convert the series to <class 'int'> when trying to create new dataframe column Mark17 3 8,389 Jan-20-2022, 05:15 PM
Last Post: deanhystad
  Create zip file from the BLOB column in ORACLE DB nnsatpute 2 1,879 Dec-31-2021, 11:00 AM
Last Post: ibreeden
  pandas pivot table: How to find count for each group in Index and Column JaneTan 0 3,226 Oct-23-2021, 04:35 AM
Last Post: JaneTan
  Data extraction from a table based on column and row names tgottsc1 1 2,359 Jan-09-2021, 10:04 PM
Last Post: buran

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020