Python Forum
Search Results
Post Author Forum Replies Views Posted [asc]
    Thread: Need help with coding in script
Post: RE: Need help with coding in script

The input JSON as your complete posted is not valied Tips use jsoncrack to check if valid and see structure. state.json Output:{ "states": [ { "state": [ { "id": [ ...
snippsat General Coding Help 8 182 6 hours ago
    Thread: Need help with coding in script
Post: RE: Need help with coding in script

It can be useful to make json data to a Pandas the DataFrame,then is easier to work with datat eg query and get a result. Example. import pandas as pd import json with open('state.json') as file: ...
snippsat General Coding Help 8 182 Yesterday, 10:23 PM
    Thread: Converting a json file to a dataframe with rows and columns
Post: RE: Converting a json file to a dataframe with row...

(Jan-29-2023, 11:02 AM)eyavuz21 Wrote: Thanks so much for your help. I have tried your code above - it gives me an empty dataframe. When I try the following code:You mess the json file to a string...
snippsat General Coding Help 13 388 Jan-29-2023, 01:56 PM
    Thread: Converting a json file to a dataframe with rows and columns
Post: RE: Converting a json file to a dataframe with row...

Use json_normalize(). Can look at a example in this post
snippsat General Coding Help 13 388 Jan-28-2023, 08:59 PM
    Thread: help how to get size of pandas dataframe into MB\GB
Post: RE: help how to get size of pandas dataframe into ...

If you search so is this a common task,so there is many soution out there. The math is simple,can write it like this to eg get it MiB. >>> b = 19647323 >>> print(f'{b} bytes is {b /...
snippsat General Coding Help 1 189 Jan-28-2023, 01:23 PM
    Thread: python print all files which contain specific word in it
Post: RE: python print all files which contain specific ...

(Jan-27-2023, 07:20 AM)mg24 Wrote: Hi Deanhystad, I liked your solution, one more helpA little mixup in names as you talking about code in my post **wink** Like this. LF = 'life' pattern = re.comp...
snippsat General Coding Help 5 355 Jan-27-2023, 11:20 AM
    Thread: Manipulating panda dataframes more python-like
Post: RE: Manipulating panda dataframes more python-like

(Jan-20-2023, 12:57 AM)badtwistoffate Wrote: Unfortunately, I don't think I'm doing it in a python-efficient way as the script has been executing for over three hours. Here's some example code. Is t...
snippsat Homework 4 408 Jan-27-2023, 02:32 AM
    Thread: Not getting Info(Title)
Post: RE: Not getting Info(Title)

Use code tag Use yield and not return and now you do not save the ouptut now,just get run info of scrapy. import scrapy class BasicsSpider(scrapy.Spider): name = 'ietf' allowed_domains = ['p...
snippsat Web Scraping & Web Development 1 207 Jan-25-2023, 10:24 PM
    Thread: python print all files which contain specific word in it
Post: RE: python print all files which contain specific ...

As mention pathlib is a better choice,for search a word i would prefer regex rather than glob. pathlib has own glob Path.glob. To give a example with regex as mention,this search for word life in file...
snippsat General Coding Help 5 355 Jan-25-2023, 07:38 PM
    Thread: Question about ImagePath.Path() in Pillow library
Post: RE: Question about ImagePath.Path() in Pillow libr...

(Jan-24-2023, 01:35 PM)dfkettle Wrote: So is there any reason to use ImagePath if you don't need to call any of its methods (compact(),getbox(), map(), toList(), transform())? In other words, simply...
snippsat General Coding Help 1 165 Jan-24-2023, 07:20 PM
    Thread: write json into a table
Post: RE: write json into a table

Try loop over the list then insert the the values. cursor = conn.cursor() for item in lst: cursor.execute("INSERT INTO tbl (id, country_name, zip) VALUES (?, ?, ?)", item) conn.commit() cursor.clo...
snippsat General Coding Help 4 348 Jan-21-2023, 09:46 PM
    Thread: painfully slow runtime when handling data
Post: RE: painfully slow runtime when handling data

The way you do it will be very slow,every time write a loop in Pandas it often the wrong approch. The way Pands is build should try to use Vectorization it will be a lot faster,look at this blog post.
snippsat General Coding Help 3 284 Jan-20-2023, 07:11 PM
    Thread: pandas dataframe into csv .... exponent issue
Post: RE: pandas dataframe into csv .... exponent issue

To avoid to be shorten to scientific notation(n-5e-06),use float_format parameter. >>> print(df.to_csv(index=False, line_terminator='\n', float_format='%.6f')) 0 0.000000 -0.000005 -1.859603 ...
snippsat General Coding Help 10 340 Jan-20-2023, 06:42 PM
    Thread: Python Pandas Syntax problem? Wrong Output, any ideas?
Post: RE: Python Pandas Syntax problem? Wrong Output, an...

mean and median can give same output it depends on input data. Read a little about the diffrence. You can also call it directly on id_values.mean(). Example. import pandas as pd data = {'PassengerId'...
snippsat General Coding Help 2 213 Jan-18-2023, 10:02 PM
    Thread: wxPython install error
Post: RE: wxPython install error

There is issues while using Python 3.11. Same on Win i did a quick test using Python 3.11 and it fails,Win and Mac use similar pre build wheels. Works fine on Pyrhon 3.10,so use that for now. Look at...
snippsat General Coding Help 3 364 Jan-17-2023, 11:04 AM
    Thread: azure TTS from text files to mp3s
Post: RE: azure TTS from text files to mp3s

Have you looked at response content print(response) to see if it's really is a binary format you get back? Here a example found online you can try. import requests import json # Replace with your Tex...
snippsat General Coding Help 2 284 Jan-17-2023, 02:20 AM
    Thread: Very simple question about filenames and backslashes!
Post: RE: Very simple question about filenames and backs...

(Jan-16-2023, 11:38 AM)garynewport Wrote: I want to remove the file extension and capture only the filename.As mention pathlib is the best choice for this, there is way for this in os module like ba...
snippsat General Coding Help 4 354 Jan-16-2023, 03:46 PM
    Thread: Set string in custom format
Post: RE: Set string in custom format

Can *unpack it like this,one of the few cases where format() is useful over f-string. >>> n = '12345678' >>> req = "{}{}{}-{}{}-{}{}{}".format(*n) >>> req '123-45-678'
snippsat General Coding Help 4 261 Jan-16-2023, 01:36 PM
    Thread: Python SSL web page scraping
Post: RE: Python SSL web page scraping

There are severals big problems here. Should not be needed now to say that you should be using Python 2.7,it has been dead💀 for 3-years now. For the scraing part the url leads to a login page and not ...
snippsat General Coding Help 1 201 Jan-13-2023, 04:11 PM
    Thread: Pyinstaller
Post: RE: Pyinstaller

Are you using frozendict in code ou try complie? Should post a code example(what version og Python/Pyisntaller used) that give this error,so we can try to see it get same error. I always run in virtua...
snippsat General Coding Help 1 212 Jan-11-2023, 03:08 PM

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020