Python Forum
Search Results
Post Author Forum Replies Views Posted [asc]
    Thread: Can i clean this code ?
Post: RE: Can i clean this code ?

(Oct-28-2023, 04:44 PM)deanhystad Wrote: Looks like you could use 2 dictionaries. code->market and market->code. zip_areas= {"010": "Springfield", "011": "Springfield" , .... ,"997": "Alaska"...
BSDevo General Coding Help 8 1,022 Oct-28-2023, 05:50 PM
    Thread: Can i clean this code ?
Post: RE: Can i clean this code ?

(Oct-28-2023, 02:49 PM)buran Wrote: BSDevo ' Wrote: I hope it explains why im using hard coded instead of loading from supported fileYou are missing the point. There is no reason why your custom co...
BSDevo General Coding Help 8 1,022 Oct-28-2023, 05:46 PM
    Thread: Can i clean this code ?
Post: RE: Can i clean this code ?

(Oct-28-2023, 04:09 AM)deanhystad Wrote: You cannot make a dictionary like that, and why would you? The space saving would be miniscule and how could you look anything up? You could make a reverse ...
BSDevo General Coding Help 8 1,022 Oct-28-2023, 02:43 PM
    Thread: Can i clean this code ?
Post: RE: Can i clean this code ?

(Oct-27-2023, 11:22 PM)Larz60+ Wrote: FYI: you can get your zipcode data here: https://www.unitedstateszipcodes.org/ I dont need zipcode data, i have. I want to minimize my code. From: "010": "Sprin...
BSDevo General Coding Help 8 1,022 Oct-27-2023, 11:43 PM
    Thread: Can i clean this code ?
Post: Can i clean this code ?

Hi, im trying to clean my code and make less of and i would like to know if its possible to clean it ( im having issues with finding solutions when i dont know what to look for ) My code: def are...
BSDevo General Coding Help 8 1,022 Oct-27-2023, 11:10 PM
    Thread: GroupBy - Sum = Error [datetime64 type does not support sum operations]
Post: RE: GroupBy - Sum = Error [datetime64 type does no...

(Oct-27-2023, 05:04 PM)deanhystad Wrote: Fine, make it an index. The problem was that you were not doing so correctly. pme_df = filtered_df[["Market", "Price"]].set_index("Market").sum() Thank You ...
BSDevo Data Science 4 3,233 Oct-27-2023, 07:22 PM
    Thread: GroupBy - Sum = Error [datetime64 type does not support sum operations]
Post: RE: GroupBy - Sum = Error [datetime64 type does no...

(Oct-26-2023, 07:22 PM)deanhystad Wrote: 1 pme_df = filtered_df.groupby(by = ["Market"], as_index = False)["Price"].sum().sort_values(by= ["Price"], ascending=False).reset_index()This is what it...
BSDevo Data Science 4 3,233 Oct-27-2023, 04:58 PM
    Thread: GroupBy - Sum = Error [datetime64 type does not support sum operations]
Post: GroupBy - Sum = Error [datetime64 type does not su...

Hi, Im trying to solve this particular issue. Im using two columns to display Price and Market. lftcolumn, rghtcolumn = st.columns((9, 1)) with lftcolumn: pme_df = filtere...
BSDevo Data Science 4 3,233 Oct-26-2023, 05:07 PM
    Thread: SORTED.group by and count average of two columns [ sum of col 1 / sum of col 2 ]
Post: RE: group by and count average of two columns [ su...

Solved. filtered_df["RPM"] = filtered_df["Rate"]/filtered_df["Miles"].groupby(filtered_df["PuState"]).transform('mean')Turns out i solved it by removing () EDIT: No , it makes incorrect calculations ...
BSDevo Data Science 1 729 Oct-23-2023, 09:47 PM
    Thread: SORTED.group by and count average of two columns [ sum of col 1 / sum of col 2 ]
Post: SORTED.group by and count average of two columns [...

Hi, im trying to group by and get an average of two columns in Pandas then display inside Streamlit_Folium chropleth.geojson map but my KPI and Map averages are different.Trying to group by states an...
BSDevo Data Science 1 729 Oct-23-2023, 07:31 PM
    Thread: Cleaning my code to make it more efficient
Post: RE: Cleaning my code to make it more efficient

(Sep-27-2023, 09:36 PM)deanhystad Wrote: This is shorter, but it is still messy. The less you have to type, the better the code. If you see that you are going to do the same thing over and over, u...
BSDevo General Coding Help 13 1,516 Sep-27-2023, 10:39 PM
    Thread: Cleaning my code to make it more efficient
Post: RE: Cleaning my code to make it more efficient

(Sep-27-2023, 07:48 PM)deanhystad Wrote: It is not really a language thing. It is a forum thing. This is a Python forum, so posters ask technical questions related to Python. The problem with thi...
BSDevo General Coding Help 13 1,516 Sep-27-2023, 08:46 PM
    Thread: Cleaning my code to make it more efficient
Post: RE: Cleaning my code to make it more efficient

Yeah, i do have a problem when trying to explain things specially when English is not my main language. My charts , pies etc will change on filter selection. in the previous posts where snippsat clean...
BSDevo General Coding Help 13 1,516 Sep-27-2023, 06:38 PM
    Thread: Cleaning my code to make it more efficient
Post: RE: Cleaning my code to make it more efficient

(Sep-26-2023, 11:53 PM)deanhystad Wrote: How about something like this: for column in df: choices = set(df[column].values) if len(choices) < 2: continue choices = st.sidebar.m...
BSDevo General Coding Help 13 1,516 Sep-27-2023, 01:38 PM
    Thread: Cleaning my code to make it more efficient
Post: RE: Cleaning my code to make it more efficient

(Sep-26-2023, 05:58 PM)deanhystad Wrote: I think your approach is all wrong. Instead of testing each column for a filter, you should make a list of filters to apply. Filtering can be done with a ...
BSDevo General Coding Help 13 1,516 Sep-26-2023, 09:51 PM
    Thread: Cleaning my code to make it more efficient
Post: RE: Cleaning my code to make it more efficient

(Sep-26-2023, 11:52 AM)snippsat Wrote: Can clean up the and not mess to this. if not any([regionas, valstija, marketas, zmogus, daiktas, dienos, menesiai, seima, augintinis, miestas, siurprizas]): ...
BSDevo General Coding Help 13 1,516 Sep-26-2023, 12:43 PM
    Thread: Cleaning my code to make it more efficient
Post: Cleaning my code to make it more efficient

Hi, as i`m new to python my code is not clean and not efficient and im looking towards faster performance while im loading my code. Im using streamlit and pandas and i have filters like this 12 times ...
BSDevo General Coding Help 13 1,516 Sep-26-2023, 10:46 AM
    Thread: Noob question
Post: RE: Noob question

I sorted out how to choose by year as i missed one option. df = df[df['PMarket'].isin(market_list)] df = df[df['PYear']==market_date] df = df[df['PYear']==market_date] <...
BSDevo Data Science 4 983 Sep-08-2023, 09:18 AM
    Thread: Noob question
Post: RE: Noob question

(Sep-07-2023, 09:55 AM)snippsat Wrote: You should post a sample of working DataFrame, you do lot explaining for the 4 line of code,but it hard to make any sense of without a example. Same problem yo...
BSDevo Data Science 4 983 Sep-07-2023, 08:11 PM
    Thread: Noob question
Post: Noob question

Hi, im new to Pandas, Python and all this awesomnes ! I learn hard way ... I have few things im confused about. Im trying to sort and visualize with graphs but separate by years. df_mc = pd.DataFr...
BSDevo Data Science 4 983 Sep-07-2023, 05:19 AM

User Panel Messages

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