Python Pandas Duplicate Header Row and Increasing File Size

I am writing a tool that will pull data from an API and save it as CSV. I want to run this daily and update my CSV, removing duplicates. Currently the data is pulled and stored fine, however I have two problems. There is a duplicate header row somewhere in my data that isn’t being… Read More Python Pandas Duplicate Header Row and Increasing File Size

Filter a CSV file with multiple conditions using PowerShell

Here is a small sample of data in a CSV file that needs to be filtered to remove all lines that contain Branch 102 or Name equals Admin. DataSource.csv branch,ID,name 102,11056,Jones 103,11057,Henry 102,22000,Admin 103,22001,Admin 102,22002,White 103,22003,George Here is the first version my PowerShell script, demo.ps1, that works – $path = "C:\users\knot22\PowerShell" Import-CSV "$($path)\DataSource.csv" | Where… Read More Filter a CSV file with multiple conditions using PowerShell

csv module splits within quotes with custom separator

I’d like the below code to avoid splitting within double quotes, but it does: import csv from io import StringIO contents = """ gene "Tagln2"; note "putative; transgelin 2 (MGD|MGI:1312985 GB|BC049861, evidence: BLASTN, 99%, match=1379)"; product "transgelin-2"; protein_id "NP_848713.1"; tag "RefSeq Select"; exon_number "4"; """ for l in csv.reader(StringIO(contents), delimiter=";", quotechar=’"’, skipinitialspace=True, quoting=csv.QUOTE_MINIMAL): print(l) outputs:… Read More csv module splits within quotes with custom separator

Reading and writing a csv file in one line

I have below code import pandas as pd (pd.read_csv(‘https://www.stats.govt.nz/assets/Uploads/Business-financial-data/Business-financial-data-September-2022-quarter/Download-data/business-financial-data-september-2022-quarter-csv.zip’) .assign(New = lambda x : ‘NEW’) .apply(lambda x : x.to_csv(x[‘New’].values[0] + ‘_File.csv’))) Basically, I wanted to use chain rule to read and write a csv file, after some modification using above lines of code. Final file name is chosen dynamically based on some value of chosen… Read More Reading and writing a csv file in one line

How can I delete a specific column in a tab seperated csv?

I found some code online that deletes a specific column by name using pandas: # import pandas with shortcut ‘pd’ import pandas as pd # read_csv function which is used to read the required CSV file data = pd.read_csv(‘TradedInstrument_20230331_test.csv’) # drop function which is used in removing or deleting rows or columns from the CSV… Read More How can I delete a specific column in a tab seperated csv?

Why export only last value in list when using writerow function

I have a list of 19 businesses retrieved from scraping website as follow: for firm in firms: name = firm.find(‘h3′, class_=’company-name’).text mst = firm.find(‘p’, class_=False).get_text(strip=True).split(‘-‘)[0].split(‘:’)[1] print(name,mst) CÔNG TY CỔ PHẦN ĐẦU TƯ THƯƠNG MẠI LUCKY HOÀNG MINH 0110306061 CÔNG TY CỔ PHẦN SUFAM VIỆT NAM 0110306304 CÔNG TY TNHH TMDV THT VIỆT NAM 0110306449 CÔNG… Read More Why export only last value in list when using writerow function

Split CSV file into multiple files sorted my colum

Hi im a Python noob and i want to make a programm to split my csv file into multiple csv files the file looks something like this: main.csv Name;Lieferung;Name;Ort;Postleitzahl somename;60072470;somename;someadress;83620 somename;60071938;somename;someadress;48691 somename;60072194;somename;someadress;13595 somename;60072194;somename;someadress;13595 somename;60072511;somename;someadress;82140 and i want the code to automaticly create multiple csv files grouped by Lieferung: 60072470.csv somename;60072470;somename;someadress;83620 60071938.csv somename;60071938;somename;someadress;48691 60072194.csv somename;60072194;somename;someadress;13595 somename;60072194;somename;someadress;13595… Read More Split CSV file into multiple files sorted my colum