Reputation: 1886
I'm trying to create a table in Python using Pandas crosstab function. I've managed to get the data to produce a table, however, it is not very readable. What I am trying to do is remove the 0s from the table.
The table looks like this at the moment:
I'm wondering if it possible to remove the 0s, or if there is a better way to produce this table.
Edit: by remove, I mean remove/don't display, in the table. Need to keep the data in the original data source.
Upvotes: 1
Views: 733
Reputation: 2239
I am not sure this will help, but you can try:
df.replace(0, np.nan)
I will give you a bunch on nan, but you will not lose the data type, just in case you want to perform any math. If this is not a problem, you can replace with the np.nan with 0. You need to import numpy as np.
Upvotes: 1
Reputation: 2940
Visualize the array as an image.
import cv2
import numpy as np
import pandas as pd
# Read data from .csv file
df = pd.read_csv('/home/stephen/Desktop/data.csv')
# Convert image to an array
img = np.array(df, np.float32)
# Scale image so values are from 0 to 1
img = img/np.amax(img)
# Resize so it's easier to see
img = cv2.resize(img, (420,420))
cv2.imshow('img', img)
cv2.waitKey()
cv2.destroyAllWindows()
Upvotes: 1