error: while concatenation in a dataframe using pandas!

0 votes

Hi Guys,

I am trying to concatenate some columns in a dataframe, but It shows me the wrong output as shown below.

X = pd.concat([x,sex,cp,fbs,restecg,slope,ca,thal,exang])

 

1 2 3 4 age chol oldpeak thalach trestbps
0 NaN NaN NaN NaN 63.0 233.0 2.3 150.0 145.0
1 NaN NaN NaN NaN 37.0 250.0 3.5 187.0 130.0
2 NaN NaN NaN NaN 41.0 204.0 1.4 172.0 130.0
3 NaN NaN NaN NaN 56.0 236.0 0.8 178.0 120.0
4 NaN NaN NaN NaN 57.0 354.0 0.6 163.0 120.0
... ... ... ... ... ... ... ... ... ...
298 1.0 NaN NaN NaN NaN NaN NaN NaN NaN
299 0.0 NaN NaN NaN NaN NaN NaN NaN NaN
300 0.0 NaN NaN NaN NaN NaN NaN NaN NaN
301 1.0 NaN NaN NaN NaN NaN NaN NaN NaN
302 0.0 NaN NaN NaN NaN NaN NaN NaN NaN
 

 

How can I solve this error?

May 5 in Python by akhtar
• 11,270 points
39 views

1 answer to this question.

0 votes

Hi@akhtar,

When we use concat function we have to pass two parameters one is value and another one is axis. This axis parameter tells how you want to concat your data in column wise or Row wise. By default concat takes Row wise means axis=0. So you have to pass axis=1 for column wise operation.

X = pd.concat([x,sex,cp,fbs,restecg,slope,ca,thal,exang],axis=1)

Hope this will help.

answered May 5 by MD
• 24,500 points

Related Questions In Python

+2 votes
2 answers

How can I replace values with 'none' in a dataframe using pandas

Actually in later versions of pandas this ...READ MORE

answered Aug 13, 2018 in Python by bug_seeker
• 15,390 points
17,459 views
0 votes
0 answers

how do sort the columns in a dataframe using the pandas?

can you give an example using dataframe? READ MORE

May 6, 2019 in Python by Waseem
• 4,530 points
66 views
0 votes
1 answer

How do I create a dataframe using a dictionary in pandas?

Hi @Hannah, You need to define your dictionary ...READ MORE

answered Nov 18, 2019 in Python by Eric
80 views
0 votes
1 answer

How to convert a Pandas GroupBy object to DataFrame in Python

g1 here is a DataFrame. It has a hierarchical index, ...READ MORE

answered Nov 12, 2018 in Python by Nymeria
• 3,540 points
17,382 views
0 votes
1 answer

How to append dataframe without index?

You have to use the ignore_index option. ...READ MORE

answered Apr 1, 2019 in Python by Robert
589 views
0 votes
1 answer

How to rename columns in pandas (Python)?

It is easy by just adding ".columns" ...READ MORE

answered Apr 30, 2018 in Data Analytics by DeepCoder786
• 1,720 points
315 views
0 votes
1 answer

What is the Difference in Size and Count in pandas (python)?

The major difference is size includes NaN ...READ MORE

answered Apr 30, 2018 in Data Analytics by DeepCoder786
• 1,720 points
979 views
0 votes
4 answers

Printing a data.frame without index - Python

.tolist() function will remove index READ MORE

answered Mar 11, 2019 in Data Analytics by nishant thakur
36,542 views
0 votes
1 answer

How to transfer multiple lines in a file using python?

Hi@akhtar, I don't know it will help you ...READ MORE

answered Mar 31 in Python by MD
• 24,500 points
70 views
0 votes
1 answer

How to crop face from a photo using cv2 in python?

Hi@akhtar, You can do this task using cv2 ...READ MORE

answered Apr 9 in Python by MD
• 24,500 points
44 views