Python Pandas – select data from csv and create new csv [duplicate]

  csv, pandas, python

I have two csv files with data, I am querying 6 part numbers from file1 against file2 to retrieve stock figures. End goal being to create a new csv. I am trying to do this using Python and pandas but struggling with how tor eference certain values. Everything i can find in the pandas document is selecting a row with .loc or a column with series. I can select the correct row but i cant figure out how to take a column value from that found row.

I also come from php so there may well be a better way of achieving this in python.

sku description
part1 part1 description
part5 part5 description
sku description stock category
part1 part1 description 10 Cat1
part2 part2 description 23 cat1
part3 part3 description 9 Cat3
part4 part4 description 14 cat2
part5 part5 description 8 Cat2
part6 part6 description 12 cat1
import pandas as pd

articles = pd.read_csv('articles.csv', delimiter=',', names = ['halfordsSku', 'description', 'feridaxSku'])
data = pd.read_csv('https://download.feridax.com/exports/feridax_stock_level.csv', delimiter=',')

resultSku = []
resultStock = []

for index, row in articles.iterrows():
    
    print(data.loc[data['PartNumb'] == row['feridaxSku']])

This code successfully returns each row, my thought process was to add the stock value and part number to arrays to then create a new dataframe in pandas and save. But i cant seem to find how to reference a single column value of an already selected row.

Source: Python Questions

LEAVE A COMMENT