Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import pandas as pd
- import csv,sys
- import matplotlib
- import matplotlib.pyplot as plt
- print("Reading file... ")
- df = pd.read_csv('test.batch.csv')
- #print(df)
- # Creating a dictionary
- data = {'Value':[0,0,0]}
- kernel_df = pd.DataFrame(data, index=['M1','M2','M3'])
- my_dict = {'dummy':kernel_df}
- my_dict2 = {'dummy':kernel_df}
- # dummy -> Value
- # M1 0
- # M2 0
- # M3 0
- for name, df_group in df.groupby('Name'):
- my_dict[name] = pd.concat(
- [g.reset_index(drop=True) for _, g in df_group.groupby('ID')['Value']],
- axis=1
- )
- def plot_dataframe(df, cnt, axes):
- df.columns = range(1, len(df.columns)+1) # Ignore the column header
- row = df.iloc[0].astype(int) # First row in the dataframe
- plt.subplot(2, 1, 1)
- print("axes=", axes)
- print("axes[0]=", axes[0])
- print("cnt=", cnt)
- print("row=", row)
- ax1 = row.plot(label=cnt, ax=axes[0], marker='o') # Line chart
- ax1.set_ylabel( 'test', fontsize=15 )
- plt.subplot(2, 1, 2)
- df2 = row.value_counts()
- df2.reindex().plot(kind='bar', label=cnt, ax=axes[1]) # Histogram
- def plot_kernels(mydict2):
- print("New dictionary for plot = ", my_dict2)
- fig,axes = plt.subplots(2,1, figsize=(20, 15))
- cnt=1
- for key in my_dict2:
- if key == 'dummy': # skip the dummy key
- continue
- df = my_dict2[key]
- print("Key is ", key, " -> df is ", df)
- plot_dataframe(df, cnt, axes)
- cnt = cnt + 1
- for ax in axes:
- ax.legend()
- plt.show()
- print("matplotlib version = ", matplotlib.__version__)
- print("pandas version = ", pd.__version__)
- print("sys version", sys.version_info)
- yax = 'bar'
- print("Original dictionary = ", my_dict)
- for k in my_dict.keys():
- if yax in k:
- # Should definitely go here
- df = my_dict[k]
- my_dict2[k] = df
- #print(df)
- plot_kernels(my_dict2)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement