I am trying to create a column using data from another column based on part of the information of that column, For example I have a list of devices:
devicename make devicevalue
switch1 cisco 0
switch1-web100 netgear 0
switch10 cisco 0
switch23 cisco 1
switch31-web200 netgear 0
switch31 cisco 1
switch40 cisco 1
The column needs have 2 variables:
- If
make == netgear(set to 0) - If
devicenameend in 20 or greater (set to 1, otherwise set to 0) - Alternatively, instead of also looking at the make the
devicenamecould be filtered bywebtoo.
I am using Pandas to open CSV file, make the edits (for some other columns) then save it, but I am having difficulty with this bit.
This is where I have gotten to, but I know it doesn't work but I've got a bit lost and I'm quite new to Python:
import pandas as pd
df = pd.read_csv('data.csv')
df['devicevalue'] = df.devicename
if 'netgear' in df.name df.set_value '0'
if str.endswith > 20 df.set_value '0'
else if df.set_value '1'