0

I have some files .py, and I am executing them with python3.10 (microsoft store app), with that files i generate some csvs but I also want to save the prints output on a txt file and the sns graphics on pngs. So how can I do it?

That is an example from a file.py

dups_nom = df_users_data['X'].value_counts(dropna=False)
dups_nom_m = df_miembros_data['X'].value_counts(dropna=False)

X = []
for ind,val in dups_nom.items():
    if val > 1:
        X.append(ind)
if len(X):
    print(f'There are {len(X)} X')
    df_users_data[df_users_data.X.isin(X)]['X'].sort_values().to_csv('C:/.../.../X.csv',sep=';')
else:
    print("There are not X")
print(dups_nom.head(len(X)))


g = sns.barplot(y=df.columns, x=df.isnull().sum(), orient = 'h')
      
for p in g.patches:
    width = p.get_width()
    plt.text(150+p.get_width(), p.get_y()+0.55*p.get_height(),width, ha='center', va='center')
  • you are missing the imports in the code. It looks like it's using pandas and matplotlib, but it would be helpful to know explicitly. If you are then saving the graphics as a .png is simple using matplotlib as it's a built in feature. As for saving the print output, the simplest way would be to append it to or re-direct it to a file when you run the program in terminal `./file.py >> file.txt` in bash, idk for windows. Otherwise you can also do it via code in the file. – ManixI Apr 12 '23 at 17:39

0 Answers0