I’m working on a Flask app to return a zip file to a user of a directory (a bunch of photos) but I don’t want to include my server directory structure in the returned zip. Currently, I have this : def return_zip(): dir_to_send = ‘/dir/to/the/files’ base_path = pathlib.Path(dir_to_send) data = io.BytesIO() with zipfile.ZipFile(data, mode=’w’) as… Read More Creating a zip file in stream without directory structure
I had a method that detects line endings def getLineEnding(filename): ret = "\r\n" with open(filename, ‘r’) as f: f.readline() ret = f.newlines return ret In order to be able to test it without using real files, I changed it to: def getLineEnding(filehandle): filehandle.readline() return filehandle.newlines And this works fine with files. But when I do… Read More How to check what lineending a StringIO file is using?
In writing dataframe to Excel spreadsheet, I want the file to have no border on the first row and column width to be auto adjusted. With the old package xlwt and xlrd, I can read the file from Pandas produced, to a new file with no border on the header. But it’s .xls (not .xlsx)… Read More Dataframe to Excel, with no border formatting, and auto column width
TLDR: How to create in Python a file object (preferably a io.TextIOWrapper, but anything with a readline() and a close() method would probably do) from a string ? I would like something like f = textiowrapper_from_string("Hello\n") s = f.readline() f.close() print(s) to return "Hello". Motivation: I have to modify an existing Python program as follows:… Read More Python: create a file object from a string
I’ve been stuck on this for longer than I would like to admit. I’m trying to use index of a list to make a new column based on the Day column. I’m sure this is super simple. Really all I am trying to do is get the day difference between today and these other days.… Read More Using an list index to create column in Pandas
2 columns dataframe as the first screenshot. I want to add new columns (by the contents in the Note column from the original dataframe) to tell if the Note column contains the new column’s header text. Example as the second screenshot. Some lines work for a few columns. When there are a lot of new… Read More Dataframe new columns to tell if the row contains column's header text
Hi I have a csv file with items like this product_id,url 100,https://url/p/Cimory-Yogurt-Squeeze-Original-120-g-745133 "1000,""https://url/p/OREO-Biskuit-Dark-&-White-Chocolate-123,5-g-559227""" 1002,https:/url/p/GARNIER-Micellar-Cleansing-Water-Sensitive-Skin-Pink-125-ml-371378 I tried using import pandas as pd productUrl = pd.read_csv(‘productUrl.csv’,sep=","quotechar=’"’) It returns back as product_id url 100 https://url/p/Cimory-Yogurt-Squeeze-Original-120-g-745133 1000,"https://url/p/OREO-Biskuit-Dark-&-White-Chocolate-123,5-g-559227" 1002 https:/url/p/GARNIER-Micellar-Cleansing-Water-Sensitive-Skin-Pink-125-ml-371378 How do I read the csv? Because the url has commas in there too. >Solution : You do not need… Read More How to read a csv file with commas in field with pandas python?