0

I'm using an excel document with 5000 rows and 37 columns to get it formatted to a level where a third part software can accept the file without any problems.

Programming in PyCharm PoorPeople Edition

The problem is simple:

If Column_value = "XYZ": excel.write(Custom Data if True) else: excel.write(Custom Data if Else)

I've been trying to solve this problem for some time now and I really can't wrap my head what am I doing wrong.

Importing the data:

excel = xlsxwriter.Workbook('excel_file.xlsx')

File is now ready for formatting, lets to this:

Plant_EquipmentProperty = excel.dropna(subset=['Description']) #ignore anything that doesn't have Description

The next stage is to remove a row if a column has a specific string in it and everything I tried so far had no results (including stack overflow ideas) which were:

  1. How to drop rows from pandas data frame that contains a particular string in a particular column?

The problem ~df.C.str.contains("XYZ") = does not compile and includes every single column

  1. Skip rows during csv import pandas

The problem - just doesn't work at all

  1. Deleting DataFrame row in Pandas based on column value

The problem - .line_race is not a thing anymore

  1. https://www.codegrepper.com/code-examples/python/check+if+value+in+column+is+null+pandas

The Problem - it's looking for null and not specifics

etc.

I've tried a numerous things and nothing seems to be as simple as if column XYZ is equal to "ABC" get rid of it.

What am I doing wrong?

  • you can try importing the excel file into a pandas dataframe where you can filter the columns. `excel=pd.read_excel('excel_file.xlsx')` then just simply filter it: `filtered_df=excel[excel['Column_Name']=='XYZ']` `filtered_df.to_excel('output.xlsx')` – Irsyaduddin Sep 05 '22 at 00:36
  • Wouldn't help me as I modify Colum A based on the value of Column B as an example – Tommy H. Sep 05 '22 at 11:09
  • then try a list comprehension? `new_col=[i if excel['Column B'][i]=='XYZ' else none for i in range(len(excel))]` `excel['Column A']=new_col` – Irsyaduddin Sep 07 '22 at 00:12

0 Answers0