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

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 :: convert 1 digit to 2 digit python 
Python :: fix ImportError: No module named PIL 
Python :: import forms 
Python :: python format currency 
Python :: python datetime yesterday 
Python :: python r squared 
Python :: python send sms 
Python :: cv2 image object to base64 string 
Python :: how to remove first row of numpy array 
Python :: python time execution 
Python :: python year month from date 
Python :: python generate secret key 
Python :: python is letter or number functin 
Python :: check key pressed pygame 
Python :: how to install panda3D 
Python :: python parsing meaning 
Python :: how to click in selenium 
Python :: check package version python 
Python :: python roll dice 100 times 
Python :: how to do label encoding in multiple column at once 
Python :: generate openai schema 
Python :: plot value counta 
Python :: print whole dataframe python 
Python :: try datetime python 
Python :: how to separate x and y from mouse position python 
Python :: flipping an image with cv2 
Python :: extract name organization using nltk 
Python :: pyttsx3 speech to mp3 
Python :: check empty dataframe 
Python :: python show image cv2 
ADD CONTENT
Topic
Content
Source link
Name
7+1 =