Reputation: 39
I'm working on these data frames, but I wonder if I can save them all in a .csv file?
li=[65, 98, 55, 62, 79, 59, 51, 90, 72, 56, 70, 62, 66, 80, 94, 79, 63, 73, 71, 85]
datos= pd.DataFrame(li)
t=datos.values.tolist()
lo=np.sort(t,axis=None)
f=pd.Series(lo).value_counts()
f1=pd.DataFrame({'frecuencias':f})
f2=f/len(lo)
f3=pd.DataFrame({'frecuencias relativa':f2})
Here I have two data frames that I would like to save in the same file. I have tried the following:
f1,f3.to_csv('vacio.csv')
but it gives me a mess or not what I expected the two tables to show one below the other, I hope your kind help.
Upvotes: 0
Views: 115
Reputation: 1531
You should concat
both the dataframe as follows:
final_df = pd.concat([f1,f3],axis=1)
then final_df
save this to csv as final_df.to_csv("test.csv",drop=True)
You can see in the csv as following output:
frecuencias frecuencias relativa
62 2 0.10
79 2 0.10
63 1 0.05
66 1 0.05
70 1 0.05
71 1 0.05
72 1 0.05
73 1 0.05
80 1 0.05
51 1 0.05
85 1 0.05
Upvotes: 1