TheDeveloperBlog.com

Home | Contact Us

C-Sharp | Java | Python | Swift | GO | WPF | Ruby | Scala | F# | JavaScript | SQL | PHP | Angular | HTML

Pandas Concatenating data

Pandas Concatenating data with What is Python Pandas, Reading Multiple Files, Null values, Multiple index, Application, Application Basics, Resampling, Plotting the data, Moving windows functions, Series, Read the file, Data operations, Filter Data etc.

<< Back to PANDAS

Concatenating the data

NumPy's concatenate data is used to concatenate two arrays either row-wise or column-wise. It can take two or more arrays of the same shape and it concatenates row-wise as a default type i.e. axis=0.

Example1:

# import numpy
import numpy as np
arr1 = np.arange(9)
arr1
arr2d_1 = array.reshape((3,3))
arr2d_1
	arr2d_1 = np.arange(10,19).reshape(3,3)
arr2d_1


# concatenate 2 numpy arrays: row-wise
np.concatenate((arr2d_1, arr2d_2))

Output:

array([[ 0,  1,  2],
       [ 3,  4,  5],
       [ 6,  7,  8],
       [10, 11, 12],
       [13, 14, 15],
       [16, 17, 18]])

Example2:

import pandas as pd

one = pd.DataFrame({'Name': ['Parker', 'Phill', 'Smith'],'id':[108,119,127]},index=['A','B','C'])
two = pd.DataFrame({'Name': ['Terry', 'Jones', 'John'],  
                    'id':[102,125,112]},
index=['A','B','C'])
print(pd.concat([one,two]))

Output:

    Name     id
A   Parker   108
B   Phill    119
C   Smith    127
A   Terry    102
B   Jones    125
C   John     112

Example3:

import pandas as pd
one = pd.DataFrame({'Name': ['Parker', 'Phill', 'Smith'],'id':[108,119,127]},index=['A','B','C'])
two = pd.DataFrame({'Name': ['Terry', 'Jones', 'John'],  
                    'id':[102,125,112]},
index=['A','B','C'])
print(pd.concat([one,two],keys=['x','y']))

Output:

 Name   id
x A  Parker  108
B   Phill119
 C   Smith  127
y A   Terry  102
 B   Jones  125
C    John  112

Next TopicPandas vs NumPy




Related Links:


Related Links

Adjectives Ado Ai Android Angular Antonyms Apache Articles Asp Autocad Automata Aws Azure Basic Binary Bitcoin Blockchain C Cassandra Change Coa Computer Control Cpp Create Creating C-Sharp Cyber Daa Data Dbms Deletion Devops Difference Discrete Es6 Ethical Examples Features Firebase Flutter Fs Git Go Hbase History Hive Hiveql How Html Idioms Insertion Installing Ios Java Joomla Js Kafka Kali Laravel Logical Machine Matlab Matrix Mongodb Mysql One Opencv Oracle Ordering Os Pandas Php Pig Pl Postgresql Powershell Prepositions Program Python React Ruby Scala Selecting Selenium Sentence Seo Sharepoint Software Spellings Spotting Spring Sql Sqlite Sqoop Svn Swift Synonyms Talend Testng Types Uml Unity Vbnet Verbal Webdriver What Wpf