Add Empty Column to pandas DataFrame in Python (2 Examples) | Attach String & NaN | float() Function

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

import pandas as pd # Import pandas

data = pd.DataFrame({'x1':range(0, 7), # Create pandas DataFrame
'x2':['x', 'y', 'y', 'x', 'y', 'y', 'x'],
'x3':range(1, 8)})
print(data) # Print pandas DataFrame

data_new1['new_col'] = '' # New column with empty string
print(data_new1) # Print new pandas DataFrame

data_new2['new_col'] = float('NaN') # New column with NaN
print(data_new2) # Print new pandas DataFrame

Follow me on Social Media:

Рекомендации по теме