Python Forum
Search Results
Post Author Forum Replies Views Posted [asc]
    Thread: List all possibilities of a nested-list by flattened lists
Post: RE: List all possibilities of a nested-list by fla...

Got that! import itertools S = [['he', 'she'], ['has'], ['1', '2'], ['watch']] print(list(itertools.product(*S))) Output: [('he', 'has', '1', 'watch'), ('he', 'has', '2', 'watch'), ('she', 'has', '...
sparkt General Coding Help 1 922 Feb-23-2023, 02:21 PM
    Thread: List all possibilities of a nested-list by flattened lists
Post: List all possibilities of a nested-list by flatten...

S = [['he', 'she'], 'has', ['1', '2'], 'watch'] A list inside the list S indicates a possibility of a statement. So there are four possibilities here: 'he has 1 watch' 'he has 2 watch' 'she has 1 w...
sparkt General Coding Help 1 922 Feb-23-2023, 06:46 AM
    Thread: I tried every way to scrap morningstar financials data without success so far
Post: RE: I tried every way to scrap morningstar financi...

It's good to learn about that, thanks! I edited the codes using BeautifulSoup and am able to get a dataframe now. Not as difficult as I thought!
sparkt Web Scraping & Web Development 2 8,269 Oct-20-2020, 05:43 PM
    Thread: I tried every way to scrap morningstar financials data without success so far
Post: I tried every way to scrap morningstar financials ...

I tried every way I can think of and search out in an attempt to scrap morningstar financials data into any processable form like csv or dataframe, for instance from here: https://financials.morningst...
sparkt Web Scraping & Web Development 2 8,269 Oct-19-2020, 05:25 PM
    Thread: Dataframe mean calculation problem: do we have to loop?
Post: RE: Dataframe mean calculation problem

I got it, though I expected something much simpler. df['C'] = 0.0 for i in df.index: df['C'][i] = df[['A', 'B']][i:].mean().mean() print(df)But do we have to use this for loop to go through all ...
sparkt General Coding Help 1 2,180 Aug-28-2020, 02:41 PM
    Thread: Dataframe mean calculation problem: do we have to loop?
Post: Dataframe mean calculation problem: do we have to ...

Suppose we have a very simple dataframe. import pandas as pd df = pd.DataFrame({'A': [1, 2, 5, 6, 7], 'B': [20, 30, 50, 90, 80]}) print(df) A B 0 1 20 1 2 30 2 5 50 3 6 90 4 7 80 The ...
sparkt General Coding Help 1 2,180 Aug-27-2020, 05:44 PM
    Thread: How to load log.txt directly into python codes?
Post: RE: How to load log.txt directly into python codes...

I got it! Thank you for your thorough explanation, this alone also saves me lots of time!
sparkt General Coding Help 6 2,986 Aug-21-2020, 03:51 PM
    Thread: How to change row 2 to column header within a dataframe
Post: RE: How to change row 2 to column header within a ...

(Aug-20-2020, 03:42 PM)Marbelous Wrote: Yes, there is an easy way built in to pandas to do exactly that. Have you looked at the docs??? https://pandas.pydata.org/pandas-docs/st...d_csv.html Take ...
sparkt General Coding Help 2 2,155 Aug-20-2020, 05:12 PM
    Thread: How to change row 2 to column header within a dataframe
Post: How to change row 2 to column header within a data...

The following would read currency exchange rate data from an excel file online, but within the workbook, table name is written on row 1, column header is written on row 2 instead. import pandas as p...
sparkt General Coding Help 2 2,155 Aug-20-2020, 03:31 PM
    Thread: How to load log.txt directly into python codes?
Post: RE: How to load log.txt directly into python codes...

OK thanks. Not so complicated about the load part but seems to me more complicated about the os part. Might go through it if I need, now seems the json part is good for me enough.
sparkt General Coding Help 6 2,986 Aug-20-2020, 03:25 PM
    Thread: How to load log.txt directly into python codes?
Post: RE: How to load log.txt directly into python codes...

(Aug-18-2020, 04:20 PM)Larz60+ Wrote: why not start with the data already in a text or json file? then it's a simple read() or json.load operation to import. I think that's exactly what I'm looking ...
sparkt General Coding Help 6 2,986 Aug-19-2020, 04:27 PM
    Thread: How to load log.txt directly into python codes?
Post: How to load log.txt directly into python codes?

I wrote a very simple program which can retrieve some data I need. It's then written to a txt file. It looks like the following. Tencentlh = ([0.675000011920929, 0.8550000190734863, 1.6699999570846...
sparkt General Coding Help 6 2,986 Aug-18-2020, 02:55 PM
    Thread: Defining multiple functions in the same def process
Post: RE: Defining multiple functions in the same def pr...

(Aug-09-2020, 05:13 PM)ndc85430 Wrote: map takes a function as its first argument and applies it to each item of the iterable passed as its second argument. In the two examples, I pass in two differ...
sparkt General Coding Help 5 2,837 Aug-09-2020, 06:19 PM
    Thread: Defining multiple functions in the same def process
Post: RE: Defining multiple functions in the same def pr...

(Aug-08-2020, 06:10 PM)Yoriz Wrote: You can return a tuple of results Thanks for the input. In that case I would have to assign "ratio" and "index" to a single result only, because ratio and index a...
sparkt General Coding Help 5 2,837 Aug-09-2020, 05:02 PM
    Thread: Defining multiple functions in the same def process
Post: Defining multiple functions in the same def proces...

I'm trying to define a function which would give multiple value outputs after some tedious calculation. Based on my current knowledge the best I can do now is to let it return a dictionary. Below is a...
sparkt General Coding Help 5 2,837 Aug-08-2020, 05:11 PM
    Thread: How to define a function to create a resorted list?
Post: RE: How to define a function to create a resorted ...

(Aug-07-2020, 05:26 PM)deanhystad Wrote: Look up sorting keys in the python documentation. They even provide examples. I wrote a 3 line script to sort you list by deviation from the mean. Used the...
sparkt General Coding Help 6 2,840 Aug-08-2020, 04:10 PM
    Thread: How to define a function to create a resorted list?
Post: RE: How to define a function to create a resorted ...

(Aug-07-2020, 05:13 PM)deanhystad Wrote: Why not use a sorting key? How does that work? Further info would be appreciated.
sparkt General Coding Help 6 2,840 Aug-07-2020, 05:21 PM
    Thread: How to define a function to create a resorted list?
Post: RE: How to define a function to create a resorted ...

Thanks a lot for the help, I feel progress!
sparkt General Coding Help 6 2,840 Aug-07-2020, 02:45 PM
    Thread: How to define a function to create a resorted list?
Post: How to define a function to create a resorted list...

After day-long trial-and-error and research I found the code from web which does what I tried to do, i.e. resorting a list according to absolute difference to a value. def sortleastdev(a, val): ...
sparkt General Coding Help 6 2,840 Aug-06-2020, 06:33 PM

User Panel Messages

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