Search
 
SCRIPT & CODE EXAMPLE
 

PYTHON

python iterate columns

for (columnName, columnData) in df.iteritems():
    print('Column Name : ', columnName)
    print('Column Contents : ', columnData.values)
    
# OUTPUT
#Column Name :  ID
#Column Contents :  [1 2 3]
#Column Name :  NAME
#Column Contents :  ['John' 'James' 'Ana']
Comment

pandas iterate columns

for name, values in df.iteritems():
    print('{name}: {value}'.format(name=name, value=values[0]))
Comment

loop through a column in pandas

for x in whatever_df["Whatever Column Name"]:
  print(x)
Comment

how to iterate over columns of pandas dataframe

for column in df:
    print(df[column])
Comment

iterate rows and columns dataframe

# importing pandas as pd
import pandas as pd
  
# dictionary of lists
dict = {'name':["aparna", "pankaj", "sudhir", "Geeku"],
        'degree': ["MBA", "BCA", "M.Tech", "MBA"],
        'score':[90, 40, 80, 98]}
 
# creating a dataframe from a dictionary
df = pd.DataFrame(dict)
 
# iterating over rows using iterrows() function
for i, j in df.iterrows():
    print(i, j)
    print()
Comment

PREVIOUS NEXT
Code Example
Python :: python multiaxis slicing 
Python :: numpy delete column 
Python :: fromkeys in python 
Python :: use loc for change values pandas 
Python :: How to Count occurrences of an item in a list in python 
Python :: Python remove punctuation from a string 
Python :: qtablewidget not editable python 
Python :: python cv2 convert image to binary 
Python :: setting urls 
Python :: unique_together what is used of it in django 
Python :: pdf to csv 
Python :: how to make a def in python 
Python :: how to check current version of library in python 
Python :: python switch case 3.10 
Python :: kill python process with bash 
Python :: python import from parent directory 
Python :: python get list of file and time created 
Python :: check how many times a substring appears in a string 
Python :: python multiple inheritance 
Python :: levenshtein distance 
Python :: pandas date range 
Python :: python del 
Python :: python remove all elemnts in list containing string 
Python :: python replace two spaces with one 
Python :: sqlite3 python 
Python :: python dictionary get 
Python :: how to find in which directory my python code is running 
Python :: read json file using python 
Python :: python mettre en minuscule 
Python :: tkinter button hide 
ADD CONTENT
Topic
Content
Source link
Name
7+1 =