Home > Blockchain >  Inserting column with specifics
Inserting column with specifics

Time:11-18

I am beginner to python with a specific question: I need to create a column name called "Plane type" for a column that contains the first 4 characters of the "TAIL_NUM" column. How can I do this. I already imported the data and I can see it. enter image description here

CodePudding user response:

Creating new columns with Pandas (assuming that's what you're talking about) is very simple. Pandas also provides common string methods. Pandas Docs, Similar SO Question

You will use 'string slicing' which is worth reading about.

df['new_col'] = 'X'

or in your case:

df['Plane type'] = df['tail_num'].str[:4]

CodePudding user response:

After viewing your code and assuming that the the column "TAIL_NUM" have string values, you can do like that:

df['Plane type'] = df["TAIL_NUM"].str[0:4]
  • Related