<jupyter_start><jupyter_text>Recuperation des données depuis la base de donné mongodb     - convert collection database in pandas<jupyter_code>def get_df(name):
    spark = pyspark.sql.SparkSession.builder\
        .appName('test-mongo')\
        .config("spark.mongodb.input.uri", "mongodb://my-mongo/trading."+name) \
        .config("spark.mongodb.output.uri", "mongodb://my-mongo/trading."+name ) \
        .getOrCreate()
    
    sc = spark.sparkContext
    rdd = spark.read.format("com.mongodb.spark.sql.DefaultSource").load()
    df = rdd.select("*").toPandas()
    print(f"convert {name} done...")
    return df
 
if __name__ == "__main__":
    NAME = ["TOTAL", "TSLA", "IBM","MSFT" ]
    data = {k:get_df(k) for k in NAME}
ibm = data['IBM']
total = data['TOTAL']
msft = data['MSFT']
tsla = data['TSLA']
total.head()
import numpy as np
import pylab 
import scipy.stats as stats
# pip install scipy
compagnys = [ibm,total, msft,tsla]
for compagny in compagnys:
    compagny.index = pd.to_datetime(compagny.date)
    compagny.drop(['date','_id'], axis=1, inplace=True)
total.head()
total.shape
compagnys_liste = ["IBM","TOTAL", "MSFT","TSLA"]
for i, compagny in enumerate(compagnys):
    plt.plot(compagny.index, compagny['close'])
    plt.title(compagnys_liste[i])
    plt.xlabel('Year')
    plt.ylabel('Price')
    plt.legend(compagnys_liste[i])
    plt.show()<jupyter_output><empty_output><jupyter_text>Vérifier la distribution normale<jupyter_code>for i in range(len(compagnys)):
    compagnys[i]['prix_chg'] = compagnys[i]['close'].pct_change()[1:]
    compagny.dropna(inplace=True, axis=0)
    stats.probplot(compagnys[i]['prix_chg'], dist="norm", plot=pylab)<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.16813639035861258, 'fraction_numerical': 0.001763668430335097, 'mean_word_length': 4.455128205128205, 'pattern_counts': {'":': 1, '<': 9, '<?xml version=': 0, '>': 9, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '2', 'dir': 'jupyter-structured-clean-dedup', 'id': '536428', 'license': 'MIT', 'n_tokens_mistral': 671, 'n_tokens_neox': 646, 'n_words': 111, 'path': 'build/workspace/model.ipynb', 'repo_name': 'francis-mujani/News_and_Trading', 'size': '1701'}