Python Forum
Iterating Through Data Frame Rows
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Iterating Through Data Frame Rows
#3
Not being a scientist, I don't have any large amounts of experimental data to process, but pandas is interesting!

Have a look here perhaps!

import pandas as pd

# open the file
xl_file = '/home/pedro/myPython/pandas/delete_row.xlsx'
df = pd.read_excel(xl_file)

"""
>>> df
   col1  col2  col3  col4  col5  col6
0   123     1     2     3     4     5
1   123     2     3     4     5     6
2   456     3     4     5     6     7
3   456     4     5     6     7     8
4   789     5     6     7     8     9
5   789     6     7     8     9    10
6   123     7     8     9    10    11

"""

# Drop a row by condition

df2 = df[df.col1 != 123]

"""
>>> df2
   col1  col2  col3  col4  col5  col6
2   456     3     4     5     6     7
3   456     4     5     6     7     8
4   789     5     6     7     8     9
5   789     6     7     8     9    10
>>>
"""
Reply


Messages In This Thread
RE: Iterating Through Data Frame Rows - by scidam - Aug-06-2020, 05:54 AM
RE: Iterating Through Data Frame Rows - by Pedroski55 - Aug-09-2021, 07:01 AM

Possibly Related Threads…
Thread Author Replies Views Last Post
  how do you style data frame that has empty rows. gsaray101 0 527 Sep-08-2023, 05:20 PM
Last Post: gsaray101
  googletrans library to translate text language for using data frame is not running gcozba2023 0 1,223 Mar-06-2023, 09:50 AM
Last Post: gcozba2023
  (Python) Pulling data from UA Google Analytics with more than 100k rows into csv. Stockers 0 1,219 Dec-19-2022, 11:11 PM
Last Post: Stockers
  How to properly format rows and columns in excel data from parsed .txt blocks jh67 7 1,874 Dec-12-2022, 08:22 PM
Last Post: jh67
  Load multiple Jason data in one Data Frame vijays3 6 1,537 Aug-12-2022, 05:17 PM
Last Post: vijays3
  conditionals based on data frame mbrown009 1 893 Aug-12-2022, 08:18 AM
Last Post: Larz60+
  Merging two Data Frame on a special case piku9290dgp 0 1,083 Mar-02-2022, 10:43 AM
Last Post: piku9290dgp
  Save data frame to .csv df.to.csv() mcva 1 1,526 Feb-03-2022, 07:05 PM
Last Post: mcva
  Move a particular row in pandas data frame to last row klllmmm 0 3,748 Dec-27-2021, 09:11 AM
Last Post: klllmmm
  The code I have written removes the desired number of rows, but wrong rows Jdesi1983 0 1,630 Dec-08-2021, 04:42 AM
Last Post: Jdesi1983

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020