Python Forum
Search Results
Post Author Forum Replies Views Posted [asc]
    Thread: Is it possible to have an apostrophe inside { } in an f-string?
Post: RE: Is it possible to have an apostrophe inside { ...

You can use chr() to convert the ASCII code 39 to an apostrophe:string = f"never say you {rc(['can', 'can' + chr(39) + 't'])} do something"
boring_accountant General Coding Help 6 9,611 Sep-04-2019, 01:26 AM
    Thread: What condition caused this True?
Post: RE: What condition caused this True?

You seem to be confusing English and Python, my friend. The basic idea in Python is that anything that follows if/elif/else are statements that are evaluated to True or False (I'm sure this isn't 100%...
boring_accountant General Coding Help 14 4,817 Aug-21-2019, 02:17 AM
    Thread: weird result trying to remove numbers from a list
Post: RE: weird result trying to remove numbers from a l...

You are modifying a list that you are looping through. Here's an idea of what is happening:Start at position 0 with value 1 Remove element at position 0, all following elements are shifted back by on...
boring_accountant General Coding Help 6 3,463 Aug-21-2019, 02:02 AM
    Thread: incremental testing in all()
Post: RE: incremental testing in all()

Quote:if it does not quit early it can still be equivalent to that code in terms of what is returned. That would not make it equivalent in terms of behaviour (i.e. "quitting early") which is part of t...
boring_accountant General Coding Help 11 4,185 Aug-19-2019, 01:02 AM
    Thread: Question about using lambda
Post: RE: Question about using lambda

Also note that the first case is not an error message. You are literally asking python to display a function, not the result of a function. This is what Python does, it outputs a message telling you t...
boring_accountant General Coding Help 4 2,489 Aug-17-2019, 02:47 AM
    Thread: valueError: expected 2d, got 1d instead
Post: RE: valueError: expected 2d, got 1d instead

As per the error message, data.wgt is a pandas.Series object. You can get the data in a numpy array, which has the 'reshape' method, by accessing the 'values' attribute.data.wgt.values.reshape(-1, 1)A...
boring_accountant Data Science 1 2,937 Aug-16-2019, 02:43 AM
    Thread: incremental testing in all()
Post: RE: incremental testing in all()

According to the Python docs, all() does quit early. Quote:all(iterable)ΒΆ Return True if all elements of the iterable are true (or if the iterable is empty). Equivalent to: def all(iterable): for...
boring_accountant General Coding Help 11 4,185 Aug-16-2019, 12:49 AM
    Thread: How replace Unnamed header column with previous
Post: RE: How replace Unnamed header column with previou...

The following function should do the trick. This won't win any beauty prize however as I just quickly hacked this together.def repeat_cols(columns): last_non_unnamed = '' if 'unnamed' in columns[0...
boring_accountant Data Science 3 5,195 Aug-15-2019, 05:10 PM
    Thread: How replace Unnamed header column with previous
Post: RE: How replace Unnamed header column with previou...

Assuming you want to replace all columns containing the string 'Unnamed' with the string 'nan', this will do:print(df) df.columns = [col if not 'Unnamed' in col else 'nan' for col in df.columns] print...
boring_accountant Data Science 3 5,195 Aug-14-2019, 11:34 PM
    Thread: assignments of function references
Post: RE: assignments of function references

Can you clarify what you want to do ? I do not understand the following:Quote:i want to have class attribute names which could otherwise be used as variables be used for function references As for yo...
boring_accountant General Coding Help 3 2,377 Aug-14-2019, 11:17 PM
    Thread: How to modify df column
Post: RE: How to modify df column

Since the third row in your example is the 2nd row of data and that Python indices are zero-based, you can slice the dataframe using [1:] as done here:print(df) df.loc[1:, 'Design'] = df.loc[1:, 'Desi...
boring_accountant Data Science 1 2,489 Aug-14-2019, 11:06 PM
    Thread: Classify URLs
Post: RE: Classify URLs

Quote:Last question, do you know if I could create a list of keywords, and if the keywords are there then is a Category x? So instead of if "/string1", there I can apply a list of keywords....or would...
boring_accountant Data Science 8 3,575 Aug-14-2019, 02:43 AM
    Thread: Classify URLs
Post: RE: Classify URLs

Hi again, A variable is just a name to which you can assign values or other objects. df_filtered is a variable of type pandas.DataFrame. As to the issue at hand, df_filtered appears to me like it sh...
boring_accountant Data Science 8 3,575 Aug-13-2019, 12:18 AM
    Thread: Random selection
Post: RE: Random selection

Ah ! Here is the error:for pirates in pirates: # <-- This line is the bad guy print pirates # Attacks List attack = ['Dodge', 'Parry', 'Thrust'] print'''What this does is it cycles ...
boring_accountant General Coding Help 6 3,018 Aug-12-2019, 01:14 AM
    Thread: Random selection
Post: RE: Random selection

I can run your code just fine using 3.x. I don't have a working installation of 2.x at hand. Can you post your full code, just to make sure the issue doesn't lie elsewhere ?
boring_accountant General Coding Help 6 3,018 Aug-12-2019, 12:48 AM
    Thread: Random selection
Post: RE: Random selection

I would assume your class is using python 3.x, where the proper syntax is:print(player) print(opponent)If using python 2.x, then:print player print opponent
boring_accountant General Coding Help 6 3,018 Aug-12-2019, 12:11 AM
    Thread: Classify URLs
Post: RE: Classify URLs

It would be helpful to see a bit more of your code, especially how you define df_filtered. From the error message you posted it looks quite simply like you didn't define df_filtered. Some possible cau...
boring_accountant Data Science 8 3,575 Aug-11-2019, 08:27 PM
    Thread: Classify URLs
Post: RE: Classify URLs

If I may, perhaps a better starting point, at least for us to be able to better help you, would be to define your classification and how your data can be matched to that classification. As far as syn...
boring_accountant Data Science 8 3,575 Aug-11-2019, 04:54 PM
    Thread: Series object error message
Post: RE: Series object error message

Unfortunately, I do not have a Quandl account and cannot be bothered to set one up. Could you perhaps output the data variable or a sample of rows so that we can see its structure. As per the error m...
boring_accountant Data Science 1 4,905 Aug-11-2019, 01:29 AM
    Thread: Create dataframe through Dictionary in pandas
Post: RE: Create dataframe through Dictionary in pandas

The following should probably do what you want.import pandas as pd df2 = { 2019 :{ 'qtr1':61000, } , 2017 :{ 'qtr1':44900,'qtr3':57000,'qtr4':59000}, 2015 :{ 'qtr1':5000,'qtr3':5000,'q...
boring_accountant Data Science 2 2,252 Aug-11-2019, 01:09 AM

User Panel Messages

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