I'm new to Python so excuse me. Back when I was into PHP/MySQL. I could loop through a table based on any parameter. Let's just say ID for simplification. Once you find the ID you can put each column into a variable. Easy...
So I created a CSV and loading into a dataframe with Pandas.
switch_id,vlan_num,vlan_desc,int_vlan,int_vlan_ip,int_vlan_mask
1,20,Legal,20,192.168.20.1,255.255.255.0
1,21,HumanResources,21,192.168.21.1,255.255.255.0
2,20,Legal,20,192.168.20.2,255.255.255.0
2,21,HumanResources,21,192.168.21.2,255.255.255.0
The code I'm using looks like this as a test to understand the functionality.
import pandas as pd
df = pd.read_csv('/Users/thenk83/Desktop/PythonCode/vlan_database.txt')
for i in df:
print(df[i][2])
The option is this:
1
22
Finance
22
192.168.22.1
255.255.255.0
How do I make it so that I can use, row['switch_id'],row['vlan_num'], etc, etc. Basically, I want to put each column in the row into a variable. I want to call out each variable myself. I don't want to put out the entire row in one variable. I can see how the row is called out but how do I select the column. So confused.
Basically, I'm wanting to configure multiple Cisco switches. Looping through each row in the dataframe and plugging in data into the configs where it's needed.
I could do this easily with Php and MySQL but it's not the same thing. So I'm confused as how to do this.
I'd prefer nothing complex. As simple as possible would be great if you can help me. I'd like to understand.