0

this code is to plot a table like a joint probability mass function.

data = np.arange(6).reshape(2,3)
summation = np.sum(data)
arr2 = np.empty((2,3), dtype='U30')
for i in range(len(data)):
    for j in range(len(data[0])):
        arr2[i][j] = r'$\dfrac{{{}}}{{{}}}$'.format(data[i][j] , summation)
pd.DataFrame(arr2)

enter image description here

is there params/settings in pandas DataFrame to plot this kind of table directly from data array?

something like this

pd.DataFrame(data, formatter=r'$\dfrac{{{}}}{{{}}}$'.format(data[i][j] , summation)

1 Answer 1

1

You could use applymap, e.g. (using an f-string):

pd = pd.applymap(lambda x: fr'$\dfrac{{{x}}}{{{summation}}}$')

Depending on your use case you could also have a look at Styling.

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.