Add Column to pandas DataFrame in Python (2 Examples) | Append List as Variable | assign() Function

preview_player
Показать описание
Python code of this video:

import pandas as pd # Load pandas library

data = pd.DataFrame({"x1":range(15, 20), # Create pandas DataFrame
"x2":["a", "b", "c", "d", "e"],
"x3":range(5, 0, - 1)})
print(data) # Print pandas DataFrame

new_col = ["new", "so_new", "very_new", "the_newest", "neeeew"] # Create list
print(new_col) # Print list
# ['new', 'so_new', 'very_new', 'the_newest', 'neeeew']

print(data_new1) # Print new DataFrame

data_new2["new_col"] = new_col # Add new column
print(data_new2) # Print new DataFrame

Follow me on Social Media:

Рекомендации по теме
Комментарии
Автор

simple and effective tutorial as always. Id love to see something on panda's styling. keep it up!

fruitshopowner