I have two pandas.DataFrame :
values = pandas.DataFrame([[0, 1], [7,5]], columns=["a", "b"], index=[1, 2])
info = pandas.DataFrame([["foo", "bar"], ["few", "tar"]], columns=["a", "b"], index=[1, 2])
values and info are settings for users so I want to print a chart by merging the dataframes cell by cell on all the columns to get something like this :
a b
1 0 : foo 1 : bar
2 7 : few 5 : tar
How can I do this without a for loop ?
You can convert values data type to str and add the two data frames with : as separator.
values.apply(lambda col: col.astype(str)) + " : " + info
# a b
#1 0 : foo 1 : bar
#2 7 : few 5 : tar
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With