0

I trust you are doing well. I am using a data frame in which there are two columns screens and it's frequency. I am trying to find out the relationship between the screen and the frequency of the appearance of the screens. Now I want to know, for all screens what are all of the frequencies as sort of a summary graph. Imagine putting all of those frequencies into an array, and wanting to study the distribution in that array. Below is my code that I have tried so far:

data = pd.read_csv('frequency_list.csv')

new_columns = data.columns.values
new_columns[1] = 'frequency'
data.columns = new_columns

import matplotlib.pyplot as plt
 %matplotlib inline

dataset = data.head(10)
dataset.plot(x = "screen", y = "frequency", kind = "bar")
plt.show()

col_one_list = unpickled_df['screen'].tolist()

col_one_arr = unpickled_df['screen'].head(10).to_numpy()

plt.hist(col_one_arr) #gives you a histogram of your array 'a'
plt.show() #finishes out the plot

Below is the screenshot of my data frame containing screen as one column and frequency as another. Can you help me to find out a way to plot a frequency distribution graph? Thanks in advance.

enter image description here

desertnaut
  • 57,590
  • 26
  • 140
  • 166
Sneha Roy
  • 81
  • 1
  • 3
  • 16
  • 1
    Can you provide your data or a small chunk if it is not confidential? you may try with GitHub or some temporary file hosting services. If possible, also include a screenshot of kind of graph you need from maybe Google images. – Zeel B Patel Feb 12 '21 at 17:50
  • 1
    hmm , might be better if we get a [mcve](https://stackoverflow.com/questions/20109391/how-to-make-good-reproducible-pandas-examples) :) I appreciate that can be tuff, but if you you're looking to generate a sample, you might want to take a look at [How to make good reproducible pandas examples](https://stackoverflow.com/questions/20109391/how-to-make-good-reproducible-pandas-examples) – anky Feb 12 '21 at 18:05

1 Answers1

0

Will a bar plot work? Here's an example:

import pandas as pd
import matplotlib.pyplot as plt

freq = [102,98,56,117]
screen = ['A','B','C','D']
df = pd.DataFrame(list(zip(screen, freq)), columns=['screen', 'freq'])

plt.bar(df.screen,df.freq)
plt.xlabel('x')
plt.ylabel('count')
plt.show()

enter image description here

a11
  • 3,122
  • 4
  • 27
  • 66