DataFrame.add doesn't respect column and row indices
See original GitHub issueIf I use DataFrame.add to add two dataframes together, the order of the rows and columns seems to be used to combine the values, rather than the column and row indices.
E.g. in the below, I think I would expect to see 4 + 20 = 24 for the Col1, r2 sum. Instead the output DataFrame does not have indices, and the sums go by column and row order.
const dfd = require("danfojs-node") // version 0.2.0
let data = {"Col1": [1, 4, 5, 0],
"Col2": [2, 0, 1, 4]}
let data2 = {"Col2": [1, 5, 20, 10], //note swapped column names
"Col1": [20, 2, 1, 2]}
let df = new dfd.DataFrame(data,{index: ["r1", "r2", "r3", "r4"]})
let df2 = new dfd.DataFrame(data2,{index: [ "r2", "r3", "r4","r5"]}) // note offset index
df.print()
df2.print()
let df_new = df.add(df2)
df_new.print()
ββββββ€ββββββββββββββββββββ€ββββββββββββββββββββ
β β Col1 β Col2 β
ββββββΌββββββββββββββββββββΌββββββββββββββββββββ’
β r1 β 1 β 2 β
ββββββΌββββββββββββββββββββΌββββββββββββββββββββ’
β r2 β 4 β 0 β
ββββββΌββββββββββββββββββββΌββββββββββββββββββββ’
β r3 β 5 β 1 β
ββββββΌββββββββββββββββββββΌββββββββββββββββββββ’
β r4 β 0 β 4 β
ββββββ§ββββββββββββββββββββ§ββββββββββββββββββββ
ββββββ€ββββββββββββββββββββ€ββββββββββββββββββββ
β β Col2 β Col1 β
ββββββΌββββββββββββββββββββΌββββββββββββββββββββ’
β r2 β 1 β 20 β
ββββββΌββββββββββββββββββββΌββββββββββββββββββββ’
β r3 β 5 β 2 β
ββββββΌββββββββββββββββββββΌββββββββββββββββββββ’
β r4 β 20 β 1 β
ββββββΌββββββββββββββββββββΌββββββββββββββββββββ’
β r5 β 10 β 2 β
ββββββ§ββββββββββββββββββββ§ββββββββββββββββββββ
βββββ€ββββββββββββββββββββ€ββββββββββββββββββββ
β β Col1 β Col2 β
βββββΌββββββββββββββββββββΌββββββββββββββββββββ’
β 0 β 2 β 22 β
βββββΌββββββββββββββββββββΌββββββββββββββββββββ’
β 1 β 9 β 2 β
βββββΌββββββββββββββββββββΌββββββββββββββββββββ’
β 2 β 25 β 2 β
βββββΌββββββββββββββββββββΌββββββββββββββββββββ’
β 3 β 10 β 6 β
βββββ§ββββββββββββββββββββ§ββββββββββββββββββββ
Issue Analytics
- State:
- Created 3 years ago
- Comments:6 (3 by maintainers)
Top Results From Across the Web
DataFrame.add doesn't respect column and row indices #101
If I use DataFrame.add to add two dataframes together, the order of the rows and columns seems to be used to combine the...
Read more >Pandas: Appending a row to a dataframe and specify its index ...
The name of the Series becomes the index of the row in the DataFrame: In [99]: df = pd.DataFrame(np.random.randn(8, 4), columns=['A','B','C','D']) In [100]:Β ......
Read more >Pandas Append β pd.DataFrame.append() | Data Independent
Pandas DataFrame.append() will append rows (add rows) of other DataFrame, Series, Dictionary or list of these to another DataFrame.
Read more >Merge, join, concatenate and compare - Pandas
You can merge a mult-indexed Series and a DataFrame, if the names of the MultiIndex correspond to the columns from the DataFrame. Transform...
Read more >How to add header row to a Pandas Dataframe?
There are basically two approaches to add a header row in Python in case the original data frame doesn't have a header.
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found

Thanks for sharing this, I do think its a separate issue though.
Stale issue message