add column to start of dataframe pandas
df.insert(loc, column, value)
add column to start of dataframe pandas
df.insert(loc, column, value)
how to add a new column to the pandas df
import pandas as pd
data = {'Name': ['Josh', 'Stephen', 'Drake', 'Daniel'],
'Height': [5.5, 6.0, 5.3, 4.9]}
'''
printing data at this point will show the following
Name Height
0 Josh 5.1
1 Stephen 6.2
2 Drake 5.1
3 Daniel 5.2
'''
df.insert(2, "Age", [20, 21, 20, 19])
'''
printing data now will show the following
Name Height Age
0 Josh 5.1 20
1 Stephen 6.2 21
2 Drake 5.1 20
3 Daniel 5.2 19
'''
Copyright © 2021 Codeinu
Forgot your account's password or having trouble logging into your Account? Don't worry, we'll help you to get back your account. Enter your email address and we'll send you a recovery link to reset your password. If you are experiencing problems resetting your password contact us