After reading the csv file through pandas, i can see the data but i want to print data one by one.
df = pd.read_csv(path, usecols = ['SKU_id','Sku_Name','icm_name'])
path here is a s3 path and the output after printing df is:
SKU_id Sku_Name icm_name
0 19637 a Blank
1 41521 b Blank
2 44241 c Blank
3 44715 d Blank
4 61256 e Blank
I'm trying to print it one by one like
0 19637 a Blank
1 41521 b Blank
...
but when i do df[0] / df[1] / df[2] ... (for loop)
it doesnt seem to do anything and compiler is giving blank. please help me out on this.
tried using a for loop to go through the df like df[0] / df[1] / df[2]
but it ain't working
CodePudding user response:
I will advise you use Pandas and the iterate
import pandas as pd
df = pd.read_csv("file.csv")
# iterate over the rows of the DataFrame
for index, row in df.iterrows():
print(row['column_name'])
Or you can also access the data for each row using the index of the DataFrame
for index, row in df.iterrows():
print(row[0])
I hope this helps.