问题
Got this:
import pandas as pd
from df import df
import matplotlib as plt
import seaborn as sns
class Data_load:
def __init__(self, df):
self.df = pd.read_csv(df, delimiter=';')
# Data information section
def get_EDA_columns(self):
return self.df.columns
def get_EDA_info(self):
return self.df.info()
def get_EDA_describe(self):
return self.df.describe()
def get_EDA_shape(self):
return self.df.shape
def get_EDA_value_counts(self):
return self.df.value_counts()
def get_EDA_isnull(self):
return self.df.isnull()
def get_EDA_dtypes(self):
return self.df.dtypes
def get_EDA_isna(self):
return self.df.isna()
def get_EDA_nunique(self):
return self.df.nunique()
# Groupby section
def get_EDA_groupby_1(self):
return self.df[["User Name", "unique date"]].groupby("User Name").size().sort_values(ascending=False).to_frame(name = 'count').reset_index()
def get_EDA_groupby_2(self):
return self.df[["col1", "User Name"]].groupby("col1").size().sort_values(ascending=False).to_frame(name = 'count').reset_index()
def get_EDA_groupby_3(self):
return self.df.groupby(["User Name", "col2", "unique date", "col1", "col3"]).agg(["count"]).reset_index()
def get_EDA_groupby_4(self):
return self.df.groupby("unique date")["User Name"].size().sort_values(ascending=False).to_frame(name = 'count').reset_index()
def get_entire_dataset(self):
return self.df
def get_drop_dipl(self):
return self.df.drop(df[df['col1'] == 'Dipl'].index)
def get_drop_bach(self):
return self.df.drop(df[df['col1'] == 'Bach'].index)
# Searched my way on internet to find a simple way of visualizing stats from parent class
import matplotlib.pyplot as plt
class Visualiser(Data_load):
def __init__(self, df):
super().__init__(df)
self.fig, self.ax = plt.subplots()
self.ln, = plt.plot(['col1'], ['col2']) *# = ??? - obviously not the right way to catch data from defs in parent class file*
self.x_data, self.y_data = [], []
plt.show()
def plot_init(self):
self.ax.set_xlim(0, 10000)
self.ax.set_ylim(0, 1000)
return self.ln
Hoped for this:
Calling for the Visualiser class in my main.py file, I only get an empty canvas as plt.show() or TypeError: string indices must be integers, if I attempt to place col values in
self.ln, = plt.plot(['col1'], ['col2'])
Anyone out there to provide an answer? Basically, I am just trying to learn how to pull a simple graph from a class file (inherited). BR Hubsandspokes
来源:https://stackoverflow.com/questions/65580088/how-do-i-make-my-plot-show-simple-input-as-loaded-from-another-class-file