Search
 
SCRIPT & CODE EXAMPLE
 

PYTHON

pandas loop through rows

for index, row in df.iterrows():
    print(row['c1'], row['c2'])

Output: 
   10 100
   11 110
   12 120
Comment

pandas iterate over a series

>>> s = pd.Series(['A', 'B', 'C'])
>>> for index, value in s.items():
...     print(f"Index : {index}, Value : {value}")

Index : 0, Value : A
Index : 1, Value : B
Index : 2, Value : C
Comment

python - iterate with the data frame

# Option 1
for row in df.iterrows():
    print row.loc[0,'A']
    print row.A
    print row.index()

# Option 2
for i in range(len(df)) : 
  print(df.iloc[i, 0], df.iloc[i, 2]) 
Comment

pandas iteration

df = pd.DataFrame({'num_legs': [4, 2], 'num_wings': [0, 2]},
...                   index=['dog', 'hawk'])
>>> df
      num_legs  num_wings
dog          4          0
hawk         2          2
>>> for row in df.itertuples():
...     print(row)
...
Pandas(Index='dog', num_legs=4, num_wings=0)
Pandas(Index='hawk', num_legs=2, num_wings=2)
Comment

how to iterate through a pandas dataframe

# creating a list of dataframe columns 
columns = list(df) 
  
for i in columns: 
  
    # printing the third element of the column 
    print (df[i][2])
Comment

PREVIOUS NEXT
Code Example
Python :: python using random module 
Python :: python print f 
Python :: selenium chrome options suppress warnings python 
Python :: select multiple dict 
Python :: confusion matrix for classification 
Python :: stop function python 
Python :: python string trim 
Python :: add a button on tkinter 
Python :: Get current cursor type and color Tkinter Python 
Python :: how to check all the elements in a list are even or not 
Python :: how to sort the dataframe in python by axis 
Python :: python get array from json 
Python :: save object pickle python 
Python :: discord bot delete messages python 
Python :: ascending, descending dict 
Python :: append extend python 
Python :: remove multiple strings from list python 
Python :: np.reshape() 
Python :: find max length of list of list python 
Python :: generate random int python 
Python :: how to get scrapy output file in json 
Python :: how to calculate the variance of all columns in python 
Python :: adding number in set in python 
Python :: pandas convert string column to int list column 
Python :: diamond shape in python 
Python :: get file in file zip python 
Python :: pandas.core.frame.DataFrame to pandas.core.series.Series 
Python :: dictionary get all keys 
Python :: how to get python list length 
Python :: python pandas how to get the dataframe size 
ADD CONTENT
Topic
Content
Source link
Name
5+4 =