Editing DataFrames
You can trivially add new columns or change the values in existing column.
Add a new column
Be sure that the column you are adding has the same indices as the old dataframe.
This is most easily accomplished by manipulating an old column and saving the value
Example:
dataframe['new_column_name'] = ms['old_column']*value
Example:
dataframe['new_column_name'] = ms['old_column1']*ms['old_column2']
Alter a column
You select a set of cells using the tools from above change their values
Note that dataframes are MUTABLE!
dataframe.loc[selection,selection] = 7
Dealing with missing data
The
dataframe.dropna()
and.fillna()
funtions are super helpful in removing/replacing missing valuesExample:
only_complete_rows = dataframe.dropna(how='any')
Example:
replace_with_0 = dataframe.fillna(value=0.0)
Last updated