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

iterate over rows dataframe

df = pd.DataFrame([{'c1':10, 'c2':100}, {'c1':11,'c2':110}, {'c1':12,'c2':120}])
for index, row in df.iterrows():
    print(row['c1'], row['c2'])
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 :: group a dataset 
Python :: python list insert 
Python :: telegram bot documentation python 
Python :: flask sqlalchemy case insensitive like 
Python :: pip ne marche pas 
Python :: sum of digits in python 
Python :: unable to import flask pylint 
Python :: Python NumPy ascontiguousarray Function Example Scalar to an array 
Python :: python use negation with maskedarray 
Python :: python logging change handler level 
Python :: remove hh:mm:ss from pandas dataframe column 
Python :: Converting a HDFDataset to numpy array 
Python :: Dictionary get both key and value. 
Python :: pandas find column with max value for each row 
Python :: Binary search tree deleting in python 
Python :: Print characters from a string that are present at an even index number 
Python :: python logging levels 
Python :: typer python 
Python :: how to take dynamic input in python 
Python :: scrapy access settings from spider 
Python :: python3 conditional with boolean 
Python :: max of empty list python 
Python :: odoo docker addons path 
Python :: best time to buy and sell stock python 
Python :: how to find the no of user for a wifi using python for ubuntu 
Python :: pure imagination 
Python :: django get form id from request 
Python :: 20 minute timer with python 
Python :: pandas select multiple columns 
Python :: datetime to timestamp 
ADD CONTENT
Topic
Content
Source link
Name
7+1 =