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, 2020 in Python by akhtar
• 38,120 points
567 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 the 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, 2020 by MD
• 94,990 points

Related Questions In Python

+2 votes
4 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,550 points
30,174 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,540 points
98 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
147 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,520 points
24,743 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
2,647 views
0 votes
1 answer

How to set dataframe based on Index Name & Column name ?

Hi@Gaurav, You can use set_index function in pandas. It allows ...READ MORE

answered Jun 29, 2020 in Python by MD
• 94,990 points
89 views
0 votes
1 answer

How to rename columns in pandas (Python)?

You can use the rename function in ...READ MORE

answered Apr 30, 2018 in Data Analytics by DeepCoder786
• 1,720 points

edited Jun 8, 2020 by MD 558 views
0 votes
1 answer

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

The major difference is "size" includes NaN values, ...READ MORE

answered Apr 30, 2018 in Data Analytics by DeepCoder786
• 1,720 points

edited Jun 8, 2020 by Gitika 1,322 views
+1 vote
3 answers

How to change/update cell value in Python Pandas dataframe?

You can use the at() method to ...READ MORE

answered Apr 8, 2019 in Python by Kunal
97,010 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, 2020 in Python by MD
• 94,990 points
152 views