Read CSV in Python with date column

I want to load a csv into python. Out of the 54 columns in the .csv, I definetly now that some of those are date columns. However, after reading the csv in the python environment with pandas df = pd.read_csv("foo.csv", encoding="utf-8") the colums that are supposed to have dates in it, are filled with really… Read More Read CSV in Python with date column

Csv reader misinterprets quotes

When I try reading my string with csv reader the output I get converts the json string to ‘{filter":"freeinternet"’, ‘region:"178307"}"’ which needs to stay "{\"filter\":\"freeinternet\",\"region\":\"178307\"}" This is what I’ve tried. I’ve even tried adding quotechar, escapechar, and trying different versions, but it results in incorrect results import csv from io import StringIO s = u"""url,forgeresponsetype,identifiers,metadata,partitionkey,sortkey,expirationdate,lastmodifieddate,redirectkey,siteid,locale,type,update_date… Read More Csv reader misinterprets quotes

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