filmov
tv
Insert Column at Specific Position of pandas DataFrame in Python (2 Examples) | Middle or Beginning

Показать описание
Python code of this video:
import pandas as pd # Import pandas library
data = pd.DataFrame({'x1':range(10, 16), # Create example DataFrame
'x2':[1, 1, 1, 1, 1, 1],
'x3':[5, 2, 6, 5, 8, 1]})
print(data) # Print example DataFrame
new_col = ['a', 'b', 'c', 'd', 'e', 'f'] # Create example list
print(new_col) # Print example list
# ['a', 'b', 'c', 'd', 'e', 'f']
print(data_new1) # Print updated data
print(data_new2) # Print updated data
Follow me on Social Media:
import pandas as pd # Import pandas library
data = pd.DataFrame({'x1':range(10, 16), # Create example DataFrame
'x2':[1, 1, 1, 1, 1, 1],
'x3':[5, 2, 6, 5, 8, 1]})
print(data) # Print example DataFrame
new_col = ['a', 'b', 'c', 'd', 'e', 'f'] # Create example list
print(new_col) # Print example list
# ['a', 'b', 'c', 'd', 'e', 'f']
print(data_new1) # Print updated data
print(data_new2) # Print updated data
Follow me on Social Media: