Search
 
SCRIPT & CODE EXAMPLE
 

PYTHON

how to add a column with more rows to a dataframe

import pandas

# Note these columns have 3 rows of values:
original = pandas.DataFrame({
    'Age':[10, 12, 13], 
    'Gender':['M','F','F']
})

# Note this column has 4 rows of values:
additional = pandas.DataFrame({
    'Name': ['Nate A', 'Jessie A', 'Daniel H', 'John D']
})

new = pandas.concat([original, additional], axis=1) 
# Identical:
# new = pandas.concat([original, additional], ignore_index=False, axis=1) 

print(new.head())

#          Age        Gender        Name
#0          10             M      Nate A
#1          12             F    Jessie A
#2          13             F    Daniel H
#3         NaN           NaN      John D
Comment

PREVIOUS NEXT
Code Example
Python :: python concatenate strings 
Python :: queue in python 
Python :: del list python 
Python :: how to define variable in python 
Python :: python check if key exist in json 
Python :: pandas create average per group 
Python :: To create a SparkSession 
Python :: flatten list 
Python :: python check if input contains letters 
Python :: python treemap example 
Python :: Appending rows to a DataFrame 
Python :: continue in python 
Python :: pandas how to drop rows with extreme values in a single column 
Python :: if and else in python 
Python :: loop through list of lists jinja 
Python :: matrix rotation in python 
Python :: pass 2d array to 1d python 
Python :: plot matrix as heatmap 
Python :: error: not well-formed (invalid token) 
Python :: web socket in python 
Python :: print all variables jupyter notebook 
Python :: django queryset multiple filters 
Python :: count element in set python 
Python :: change time format pm am in python 
Python :: split string to list 
Python :: get data from model with field name in django 
Python :: bubblesort python 
Python :: combining strings in python 
Python :: python merge two array into one 
Python :: for char in string python 
ADD CONTENT
Topic
Content
Source link
Name
1+7 =