0

I have below python code and I want to get the memory usage in each line,

import numpy as np
import pandas as pd
import matplotlib.pyplot as plt
import seaborn as sns; sns.set()
uniform_data = np.random.rand(10, 12)
ax = sns.heatmap(uniform_data, cbar_kws={'ticks': [0, 2, 4, 6, 8, 10]}, vmin=0, vmax=10) 
plt.show()


#Create a DataFrame
d = {'Name':['Alisa','Bobby','Cathrine','Madonna','Rocky','Sebastian','Jaqluine',
   'Rahul','David','Andrew','Ajay','Teresa'],
   'Score1':[62,47,55,74,31,77,85,63,42,32,71,57],
   'Score2':[89,87,67,55,47,72,76,79,44,92,99,69]}


df = pd.DataFrame(d)
col_mean=df.mean()
col_std=df.std()
get_disc=df.describe()

I tried below, But I am not getting anything.

from memory_profiler import profile
@profile
import numpy as np
import pandas as pd
import matplotlib.pyplot as plt
import seaborn as sns; sns.set()
uniform_data = np.random.rand(10, 12)
ax = sns.heatmap(uniform_data, cbar_kws={'ticks': [0, 2, 4, 6, 8, 10]}, vmin=0, vmax=10) 
plt.show()


#Create a DataFrame
d = {'Name':['Alisa','Bobby','Cathrine','Madonna','Rocky','Sebastian','Jaqluine',
   'Rahul','David','Andrew','Ajay','Teresa'],
   'Score1':[62,47,55,74,31,77,85,63,42,32,71,57],
   'Score2':[89,87,67,55,47,72,76,79,44,92,99,69]}


df = pd.DataFrame(d)
col_mean=df.mean()
col_std=df.std()
get_disc=df.describe()

1 Answer 1

2

profile is a decorator, so you need to wrap your script in a function:

from memory_profiler import profile
@profile
def everything():    
    import numpy as np
    import pandas as pd
    import matplotlib.pyplot as plt
    import seaborn as sns; sns.set()
    uniform_data = np.random.rand(10, 12)
    ax = sns.heatmap(uniform_data, cbar_kws={'ticks': [0, 2, 4, 6, 8, 10]}, vmin=0, vmax=10) 
    plt.show()


    #Create a DataFrame
    d = {'Name':['Alisa','Bobby','Cathrine','Madonna','Rocky','Sebastian','Jaqluine',
       'Rahul','David','Andrew','Ajay','Teresa'],
       'Score1':[62,47,55,74,31,77,85,63,42,32,71,57],
       'Score2':[89,87,67,55,47,72,76,79,44,92,99,69]}


    df = pd.DataFrame(d)
    col_mean=df.mean()
    col_std=df.std()
    get_disc=df.describe()

everything()
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.