Skip to Main Content

Python for Basic Data Analysis: PD.4 Assigning Data

Get started on your learning journey towards data science using Python. Equip yourself with practical skills in Python programming for the purpose of basic data manipulation and analysis.

Assigning Data

Pandas also allows for assignment of data through simple call methods. This allows for the creation of new columns and for some changes to the data. We can do this assigning a constant or iterable of variables.

We can make the whole net_sales column to zero through this simple code:

df['net_sales']=0

Activity: Assigning Data

Try obtaining these outputs!

1. Change the entire order_fufilled column to True

2. Create a new column in the data frame which ranks the rows in decreasing order

Answers for Activity: Assigning Data

import pandas as pd
df=pd.read_csv("Retail dataset.csv")

#1. Change the entire order_fufilled column to True
df['order_fufilled']=True
#2. Create a new column in the data frame which ranks the rows in decreasing order
df['new_column']=range(len(df), 0, -1)

Video Guides