Splitting And Concatenating Dataframes In Python Pandas For Plotting With Rpy2
I have a question about pandas dataframes in Python: I have a large dataframe df that I split into two subsets, df1 and df2. df1 and df2 together do not make up all of df, they ar
Solution 1:
Certainly you can simplify by using:
df1['label'] = 'df1'
(rather than df1["label"] = len(df1.index) * ["df1"]
.)
If you find yourself doing this a lot, why not create your own function? (something like this):
plot_dfs(dfs):
for i, dfin enumerate(dfs):
df['label'] = 'df%s' % i+1 # note: this *changes* df
melted_df = pd.concat(dfs)
# plot parameters from melted_df and colour them by df1 or df2
ggplot2.ggplot(melted_df) + ggplot2.ggplot(aes_string(..., colour="label"))
return# the melted_df or ggplot ?
Post a Comment for "Splitting And Concatenating Dataframes In Python Pandas For Plotting With Rpy2"