Profilo di MikeI

Nome MikeI
Indirizzo email n/a
Messaggi10
  • Re: from tkinter import * - In linux Funziona solo su IDLE e su microsoft no - errore "ImportError: cannot import name Entry"
    Forum >> Programmazione Python >> GUI
    Può essere un'importazione circolare tra i tuoi file di moduli e modelli. Dovrai rifattorizzare la circolarità, o se davvero non puoi farlo dovrai spostarti dove è usato.
  • Come creare un dataframe da una pagina html o da un ResultSet di beautifulsoup?
    Forum >> Principianti
    All'interno di un oggetto zuppa ho preso tutto il testo della divisione `inner_left2` dove ci sono articoli e date e voglio ottenere tutti gli articoli e le date in un dataframe. Sembra che gli articoli e le date siano nel tag `span`. Allora ho fatto:







        page = requests.get('https://www.abcbourse.com/marches/news_valeur.aspx?p=1&s=DJIAx')
        # Create a BeautifulSoup object
    
        soup = BeautifulSoup(page.text, 'html.parser')
    
        actualites_ws = soup.find(class_='inner_left2')
    
        articles_list = actualites_ws.find_all('span')
    








    Questo dà il seguente:




        [<span class="n12">DJIA - <a href="/marches/aaz.aspx?M=usau"><img alt="" class="tipt" height="12" src="/game/flag/US.gif" title="USA" width="18"/></a></span>,
    
         <span class="quote_upb"><img alt="" height="20" src="/5/quote_up_fl.png" width="30"/>0,57%</span>,
    
         <span class="lh24">
    
         <span class="mr5">16/01/19 22:30</span>
    
         <a href="wall-street-finit-en-hausse-goldman-sachs-et-bank-of-america-a-l-honneur_459575_DJIAx.aspx">Wall Street finit en hausse, Goldman Sachs et Bank of America à l'honneur</a> (AFP)<br/>
    
         </span>,
    
         <span class="mr5">16/01/19 22:30</span>,
    
         <span class="lh24">
    
         <span class="mr5">16/01/19 16:14</span>
    
         <a href="wall-street-soutenue-par-les-resultats-de-banques-ouvre-en-hausse_459537_DJIAx.aspx">Wall Street, soutenue par les résultats de banques, ouvre en hausse</a> (AFP)<br/>
    
         </span>,
    
        ...
    






    Ma quando provo a trasformarlo in un dataframe, non funziona:







        >>>df = pd.read_html(articles_list)
    
        TypeError: Cannot read object of type 'ResultSet'
    






















    --- Ultima modifica di MikeI in data 2019-01-17 11:29:46 ---
  • Keras si avvia automaticamente nel backend quando eseguo jupyter.
    Forum >> Principianti
    Buonggiorno !

    Ogni volta che eseguo il jupyter notebook, viene lanciato questo:

    C:\WINDOWS\system32>python C:ProgramData\Anaconda3\etc\keras\load_config.py 1>temp.txt

    C:\WINDOWS\system32>set /p KERAS_BACKEND= 0<temp.txt

    C:\WINDOWS\system32>del temp.txt

    C:\WINDOWS\system32>python -c "import keras" 1>nul 2>&1

    Terminate batch job (Y/N)? Y

    E lo fermo.

    È un po 'strano Sai perché lo lancia?
  • Come unire colonne di un dataframe in una?
    Forum >> Principianti
    Buongiorno !



    Ho un dataframe con diverse colonne contenenti tabelle e vorrei riunirle in una.









    Per esempio trasformalo in qualcosa del seguente modulo :






    "Prices" è un'altra colonna che voglio aggiungere in seguito.




    --- Ultima modifica di MikeI in data 2019-01-14 11:59:56 ---
  • Come chiamare un url e aggregare i risultati in modo ricorsivo?
    Forum >> Principianti
    Buongiorno,



    Voglio recuperare in un dataframe il massimo di articoli da una certa data.

    Per il momento posso solo disegnare 20 titoli del giorno. Penso che sia il limite. Ho messo in colonna la fonte e il titolo e ho indicizzato la data.

    import requests
    
    
    
    
    
    url = ('https://newsapi.org/v2/everything?'
    
           'language=en&'
    
           'from=2018-12-07&'
    
           'to=2018-12-07&'
    
           'sources=financial-times,australian-financial-review,reuters,the-times-of-india&'
    
           'apiKey=de9e19b7547e44c4983ad761c104278f')
    
    
    
    
    response = requests.get(url)
    
    
    
    
    
    
    import pandas as pd
    
    from pandas.io.json import json_normalize
    
    
    
    
    # using the pandas.io.json.json_normalize() function; 
    
    # it can produce a dataframe for you from list-and-dictionaries structure typically loaded from a JSON source.
    
    df = json_normalize(response.json(), 'articles')
    
    
    
    
    # make the datetime column a native type, and add a date-only column
    
    df['publishedAt'] = pd.to_datetime(df['publishedAt'])
    
    df['date'] = df['publishedAt'].dt.date
    
    
    
    
    # move source dictionary into separate columns rather than dictionaries
    
    source_columns = df['source'].apply(pd.Series).add_prefix('source_')
    
    df = pd.concat([df.drop(['source'], axis=1), source_columns], axis=1)
    
    
    
    
    
    df[['date', 'source_name', 'title']].set_index('date').sort_values(['date', 'source_name'])
    

    Cosa mi dà





    2018-12-07Financial TimesPound exodus: Brexit drives away US and Asia i...2018-12-07Financial TimesTillerson says Trump paid little heed to the law2018-12-07Financial TimesAirbnb rentals in London block sparks call for...2018-12-07ReutersU.S. accuses Huawei CFO of Iran sanctions cove...2018-12-07ReutersNFL notebook: Flacco questionable, could be ba...2018-12-07ReutersNFL notebook: Flacco questionable, could be ba...2018-12-07ReutersBrazil's Temer announces 'intervention' in sta...2018-12-07ReutersBoxing: WBC sanctions direct rematch between W...2018-12-07ReutersBoxing: WBC sanctions direct rematch between W...2018-12-07ReutersBrazil's Temer announces 'intervention' in sta...2018-12-07ReutersEx-Trump campaign chair lied to investigators ...2018-12-07ReutersMueller: ex-Trump campaign chair lied to inves...2018-12-07ReutersGerman finmin looking at Deutsche, Commerzbank...2018-12-07ReutersMany U.S.-bound caravan migrants disperse as a...2018-12-07The Times of IndiaLive 1st Test India vs Australia: Rain delays ...2018-12-07The Times of IndiaPlan to prosecute Asthana legally vetted: Verm...2018-12-07The Times of IndiaLS members’ MPLADS funds for 2018-19 not yet a...2018-12-07The Times of IndiaUS: Trump lawyer met Russian offering 'politic...2018-12-07The Times of IndiaThe Latest: Manafort testified before grand ju...2018-12-07The Times of IndiaThe Latest: Prosecutors say Manafort lied abou...



    Come ottenere 20 risultati da queste fonti indicizzati ogni giorno?

    Cioè, nella seguente forma:





    pricesarticles2007-01-0112469What Sticks from '06. Somalia Orders Islamist...2007-01-0212472Heart Health: Vitamin Does Not Prevent Death ...2007-01-0312474Google Answer to Filling Jobs Is an Algorithm...2007-01-0412480Helping Make the Shift From Combat to Commerc...2007-01-0512398Rise in Ethanol Raises Concerns About Corn as...




  • Re: “Access to this API has been disallowed” durante l'interrogazione Financial Times'
    Forum >> Principianti
    perfetto !!
  • Re: “Access to this API has been disallowed” durante l'interrogazione Financial Times'
    Forum >> Principianti
    Grazie per il tuo aiuto,



    Ho provato con un altro recente articolo di FT e ho lo stesso errore.




    Per la chiave API l'ho inserito in C: \ Users \ antoi sotto il nome di .ft.key. Non ho provato con una variabile di ambiente. So come farlo ma non l'ho mai fatto.




    Per lo screenshot ho cercato di seguire le istruzioni il più possibile. Tuttavia non ho trovato come posizionare la chiave nonostante abbia seguito esattamente le istruzioni :




    Copy your API Key from the email sent to you in the previous stepEnter a Key and a ValueClick AddClick Add
  • Filtra un dizionario per chiavi
    Forum >> Principianti
    Voglio importare articoli da tutte le fonti in tutto il mondo a partire da una certa data.



    import requests
    url = ('https://newsapi.org/v2/top-headlines?'
    'country=us&'
    'apiKey=de9e19b7547e44c4983ad761c104278f')
    response = requests.get(url)

    response_dataframe = pd.DataFrame(response.json())

    articles = {article for article in response_dataframe['articles'] if article['publishedAt'] == '2019-01-04T11:30:00Z'}
    print(articles)


    Ma ottengo :



    ---------------------------------------------------------------------------
    TypeError Traceback (most recent call last)
    <ipython-input-84-0f21f2f50907> in <module>
    2 response_dataframe['articles']1['publishedAt']
    3
    ----> 4 articles = {article for article in response_dataframe['articles'] if article['publishedAt'] >= '2018-01-04T11:30:00Z'}
    5 print(articles)

    <ipython-input-84-0f21f2f50907> in <setcomp>(.0)
    2 response_dataframe['articles']1['publishedAt']
    3
    ----> 4 articles = {article for article in response_dataframe['articles'] if article['publishedAt'] >= '2018-01-04T11:30:00Z'}
    5 print(articles)

    TypeError: unhashable type: 'dict'






  • Re: “Access to this API has been disallowed” durante l'interrogazione Financial Times'
    Forum >> Principianti
    Ecco il wrapper API e qui i documenti ufficiali del Financial Times.
  • “Access to this API has been disallowed” durante l'interrogazione Financial Times'
    Forum >> Principianti
    Buonggiorno, come ottenere articoli FT tramite la loro API?



    Dopo aver chiesto una chiave, ho utilizzato un wrapper API python attorno alla loro API di contenuto, v2. Quindi ho eseguito quanto segue:




    from pyft import FT

    ft = FT()
    # the id can be pulled from the slug url of an FT.com story
    content = ft.get_content("6f2ca3d6-86f5-11e4-982e-00144feabdc0")
    print(content)




    E ottenuto:




    {'error': 'Access to this API has been disallowed'}

    Quindi ho seguito le istruzioni ufficiali ma ho ottenuto lo stesso errore: