Python Forum
frequency tables - Printable Version

+- Python Forum (https://python-forum.io)
+-- Forum: Python Coding (https://python-forum.io/forum-7.html)
+--- Forum: Homework (https://python-forum.io/forum-9.html)
+--- Thread: frequency tables (/thread-31286.html)



frequency tables - Tink - Dec-02-2020

Hello I am trying to get a frequency table with 3 but I can only get it to print 1 at a time. Can Anyone help?

Using the code cell below, create and print three frequency tables of the amino acid letters in each of the positions 222, 439 and 614.

#dataset:

import pandas as pd
from pandas.api.types import CategoricalDtype

# Read in SARS-CoV-2 Spike Protein Sequences into a pandas dataframe
spike_df = pd.read_csv('spike_proteins.csv')

# Set the type of the variable month_name as categorical ordinal so that plots and tables are ordered chronologically
cat_type = CategoricalDtype(categories=['January', 'February', 'March', 'April', 'May', 'June', 'July', 'August', 'September', 'October', 'November', 'December'], ordered=True)
spike_df['month_name'] = spike_df['month_name'].astype(cat_type)

# Output the first 10 rows
print(spike_df.head(10))

# Output the number of rows and columns
spike_df.shape
#my_code
import numpy as np
import pandas as pd
my_tab = pd.crosstab(index=spike_df["position_222"],
                    columns = "count")
my_tab