Re: Import csv file on django view

2020-07-25 Thread Ronaldo Mata
Hi Naresh Jonnala. Yes, it's work to detect delimiter on csv file, But still I don't know how to detect what is the current encoding of csv file 樂 I need to know how to implement a good uploading csv file view on django -- You received this message because you are subscribed to the Google

Re: Import csv file on django view

2020-07-25 Thread Naresh Jonnala
Hi, I am not sure this will help or not, Still i want add a peace of code. sniffer = csv.Sniffer() dialect = sniffer.sniff() dialect.__dict__ mappingproxy({'__module__': 'csv', '_name': 'sniffed', 'lineterminator': '\r\n', 'quoting': 0, '__doc__': None, 'doublequote': False, 'delimiter': ',',

Re: Import csv file on django view

2020-07-24 Thread Liu Zheng
Yes. You are right. Pandas' default behavior is as following: encoding = sys.getsystemencoding() or "utf-8" I tried to open a simple csv encoded into "utf16-LE" (popular on windows), and got the following error: UnicodeDecodeError: 'utf-8' codec can't decode byte 0xff in position 0: invalid

Re: Import csv file on django view

2020-07-24 Thread Ronaldo Mata
Hi Pandas require knows the encoding and delimiter previously when you use pd.read_csv(filepath, encoding=" ", delimiter=" ") I think that is the same 樂 El vie., 24 de julio de 2020 3:42 p. m., Jani Tiainen escribió: > Hi, > > I highly can recommend to use pandas to read csv. It does pretty

Re: Import csv file on django view

2020-07-24 Thread Jani Tiainen
Hi, I highly can recommend to use pandas to read csv. It does pretty good job to guess a lot of things without extra config. Of course it's one more extra dependency. pe 24. heinäk. 2020 klo 17.09 Ronaldo Mata kirjoitti: > Yes, I will try it. Anythin I will let you know > > El mié., 22 de

Re: Import csv file on django view

2020-07-24 Thread Ronaldo Mata
Yes, I will try it. Anythin I will let you know El mié., 22 de julio de 2020 12:24 p. m., Liu Zheng escribió: > Hi, > > Are you sure that the file used for detection is the same as the file > opened and decoded and gave you incorrect information? > > By the way, ascii is a proper subset of

Re: Import csv file on django view

2020-07-22 Thread Liu Zheng
Hi, Are you sure that the file used for detection is the same as the file opened and decoded and gave you incorrect information? By the way, ascii is a proper subset of utf-8. If chardet said it ascii, decoding it using utf-8 should always work. If your file contains non-ascii UTF-8 bytes,

Re: Import csv file on django view

2020-07-22 Thread Ronaldo Mata
Hi Kovy, this is not solved. Liu Zheng but using chardet(request.FILES['file'].read()) return encoding "ascii" is not correct, I've uploaded a file using utf-7 as encoding for example and the result is wrog. and then I tried request.FILES['file'].read().decode('ascii') and not work return bad

Re: Import csv file on django view

2020-07-22 Thread Liu Zheng
What i meant was that you can only feed binary data or binary handlers to chardet. You can decode the binary data according to the detection results afterward. On Wed, 22 Jul 2020 at 11:11 PM, Liu Zheng wrote: > Hi, glad you solved the problem. Yes, both the request.FILES[‘file’] and > the

Re: Import csv file on django view

2020-07-22 Thread Liu Zheng
Hi, glad you solved the problem. Yes, both the request.FILES[‘file’] and the chardet file handler are binary handlers. Binary handler presents the raw data. chardet takes a sequence or raw data and then detect the encoding format. With its prediction, if you want to open that puece of data in text

Re: Import csv file on django view

2020-07-22 Thread Kovy Jacob
I’m confused. I don’t know if I can help. > On Jul 22, 2020, at 11:11 AM, Liu Zheng wrote: > > Hi, glad you solved the problem. Yes, both the request.FILES[‘file’] and the > chardet file handler are binary handlers. Binary handler presents the raw > data. chardet takes a sequence or raw data

Re: Import csv file on django view

2020-07-22 Thread Kovy Jacob
Cool! I’m so happy I was able to help you!! Good luck! > On Jul 22, 2020, at 11:11 AM, Liu Zheng wrote: > > Hi, glad you solved the problem. Yes, both the request.FILES[‘file’] and the > chardet file handler are binary handlers. Binary handler presents the raw > data. chardet takes a sequence

Re: Import csv file on django view

2020-07-22 Thread Kovy Jacob
That’s probably not the proper answer, but that’s the best I can do. Sorry :-( > On Jul 22, 2020, at 10:46 AM, Ronaldo Mata wrote: > > Yes, the problem here is that the files will be loaded by the user, so I > don't know what delimiter I will receive. This is not a base command that I > am

Re: Import csv file on django view

2020-07-22 Thread Kovy Jacob
Maybe first use the standard file.open to save the file to a variable, search that variable for the different delimiters using standard string manipulation vichulu, and then open it using the corresponding delimiter. > On Jul 22, 2020, at 10:39 AM, Ronaldo Mata wrote: > > Hi Kovy, I'm using

Re: Import csv file on django view

2020-07-22 Thread Ronaldo Mata
Yes, the problem here is that the files will be loaded by the user, so I don't know what delimiter I will receive. This is not a base command that I am using, it is the logic that I want to incorporate in a view El mié., 22 jul. 2020 a las 10:43, Kovy Jacob () escribió: > Ah, so is the problem

Re: Import csv file on django view

2020-07-22 Thread Kovy Jacob
Ah, so is the problem that you don’t always know what the delimiter is when you read it? If yes, what is the use case for this? You might not need a universal solution, maybe just put all the info into a csv yourself, manually. > On Jul 22, 2020, at 10:39 AM, Ronaldo Mata wrote: > > Hi Kovy,

Re: Import csv file on django view

2020-07-22 Thread Ronaldo Mata
Hi Kovy, I'm using csv module, but I need to handle the delimiters of the files, sometimes you come separated by "," others by ";" and rarely by "|" El mié., 22 jul. 2020 a las 10:28, Kovy Jacob () escribió: > Could you just use the standard python csv module? > > On Jul 22, 2020, at 10:25 AM,

Re: Import csv file on django view

2020-07-22 Thread Kovy Jacob
Could you just use the standard python csv module? > On Jul 22, 2020, at 10:25 AM, Ronaldo Mata wrote: > > Hi Liu thank for your answer. > > This has been a headache, I am trying to read the file using csv.DictReader > initially i had an error trying to get the dict keys when iterating by

Re: Import csv file on django view

2020-07-22 Thread Ronaldo Mata
Hi Liu thank for your answer. This has been a headache, I am trying to read the file using csv.DictReader initially i had an error trying to get the dict keys when iterating by rows, and i thought it could be encoding (for this reason i wanted to prepare the view to use the correct encoding). for

Re: Import csv file on django view

2020-07-21 Thread Liu Zheng
Hi. First of all, I think it's impossible to perfectly detect encoding without further information. See the answer in this SO post: https://stackoverflow.com/questions/436220/how-to-determine-the-encoding-of-text There are many packages and tools to help detect encoding format, but keep in

Import csv file on django view

2020-07-20 Thread Ronaldo Mata
How to deal with encoding when you try to read a csv file on view. I have a view to upload csv file, in this view I read file and save each row as new record. My bug is when I try to upload a csv file with a differente encoding (not UTF-8) how to handle this on django (using request.FILES) I