#๐Ÿ”’ I need help with join 2 dataframes

38 messages ยท Page 1 of 1 (latest)

blazing stirrupBOT
#

@arctic berry

Python help channel opened

Remember to:

  • Ask your Python question, not if you can ask or if there's an expert who can help.
  • Show a code sample as text (rather than a screenshot) and the error message, if you've got one.
  • Explain what you expect to happen and what actually happens.

:warning: Do not pip install anything that isn't related to your question, especially if asked to over DMs.

arctic berry
#

When i try do it, it looks very weird

#

age sex cp trestbps chol fbs restecg thalach exang oldpeak ...
0 63 1 1 145 233 1 2 150 0 2.3 ...
0 55 1 1 140 244 0 2 138 0 2.3 ...
0 66 0 4 160 255 0 0 172 1 1.4 ...
1 67 1 4 160 286 0 2 108 1 1.5 ...
2 67 1 4 120 229 0 2 129 1 2.6 ...
.. ... ... .. ... ... ... ... ... ... ... ...
298 52 1 1 118 186 0 2 190 0 0.0 ...
299 43 0 4 132 341 1 2 136 1 3.0 ...
300 65 1 4 135 254 0 2 127 0 2.8 ...
301 48 1 4 130 256 1 2 150 1 0.0 ...
302 63 0 4 150 407 0 2 154 0 4.0 ...

 additional_chol_additional  additional_fbs_additional  \

0 220.0 1.0
0 220.0 1.0
0 220.0 1.0
1 240.0 0.0
2 260.0 1.0
.. ... ...
298 NaN NaN
299 NaN

#

additional same colums, i dont understand how to make information be in same ones

#

with join

copper sequoia
arctic berry
#

no,no, i meant additional_fbs_additional, i want it be just in colum fbs

#

this information, i dont want creat new ones

copper quail
#

@arctic berry what are the names of the two dataframes?

arctic berry
#

result = result.join(additional_data, rsuffix='_right') i try that but

copper sequoia
#

can you also show the code you're using? maybe the 2 dfs' columns you're trying to join as well

copper quail
arctic berry
#

yea

#

additional_data = pd.DataFrame({
'age': [40, 35, 50],
'sex': [0, 1, 1],
'cp': [2, 3, 1],
'trestbps': [130, 125, 140],
'chol': [220, 240, 260],
'fbs': [1, 0, 1],
'restecg': [0, 1, 2],
'thalach': [150, 155, 160],
'exang': [0, 1, 0],
'oldpeak': [1.0, 1.5, 2.0],
'slope': [1, 2, 2],
'ca': [0, 1, 0],
'thal': ['fixed', 'reversible', 'normal'],
'target': [0, 1, 0]
})
result = result.join(additional_data, rsuffix='_right') and other data frame in file csv

copper quail
#

@arctic berry please show the result of print(result.index)

#

though it looks like these are additional rows you want to add. whereas join and merge are for adding columns.

#

so you need to use pd.concat

strange field
#

I think you're looking for pd.concat, yeah

arctic berry
#

Index([ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9,
...
295, 296, 297, 298, 299, 300, 301, 302, 0, 0],
dtype='int64', length=305)

copper quail
#

!docs pandas.concat

blazing stirrupBOT
#

pandas.concat(objs, *, axis=0, join='outer', ignore_index=False, keys=None, levels=None, names=None, verify_integrity=False, sort=False, copy=None)```
Concatenate pandas objects along a particular axis.

Allows optional set logic along the other axes.

Can also add a layer of hierarchical indexing on the concatenation axis, which may be useful if the labels are the same (or overlapping) on the passed axis number.
arctic berry
#

i mean, i can but task make me do it with join

#

xd

#

i did it with contat before, but this one asked with join

copper quail
arctic berry
#

Create another DataFrame structure, fill it with arbitrary data and connect it vertically with the current structure (join). thats the task

#

i think most second, that they asked for impossible thing bc i tried everything

#

with join

copper sequoia
copper quail
#

you also need as many rows as there are rows in the dataframe you want to join to.

#

(at least ideally.)

arctic berry
#

so i need make completely new columns?

copper quail
#

well, why would you want two age columns in the same dataframe? what would that even mean?

#

if each row represents a person, how would they have more than one age?

arctic berry
#

well. true

#

i think i get it, let me try

blazing stirrupBOT
#
Python help channel closed

This help channel has been closed and it's no longer possible to send messages here. If your question wasn't answered, feel free to create a new post in #1035199133436354600. To maximize your chances of getting a response, check out this guide on asking good questions.