Profile picture

Add Column to Dataframe From List

Last updated: May 26th, 20202020-05-26Project preview
In [1]:
import pandas as pd
In [2]:
df = pd.read_csv('data.csv')
In [3]:
df.head()
Out[3]:
contact.id email
0 abc_141073000005320763 jack@example.org
1 abc_141073000005320764 nick@example.de
2 abc_141073000005320765 juli@example.com
In [4]:
l = len(df)
b = []

for x in range(l):
    s = df['email'][x]
    if '.de' in s:
        a = 'de'
    else:
        a = 'null'
    b.append(a)

df['de'] = b
In [5]:
df.head()
Out[5]:
contact.id email de
0 abc_141073000005320763 jack@example.org null
1 abc_141073000005320764 nick@example.de de
2 abc_141073000005320765 juli@example.com null
In [6]:
df.to_csv('out.csv')
Notebooks AI
Notebooks AI Profile20060