A column is a labeled vertical sequence of values in a pandas data frame. It represents one attribute of every record, while each row represents one record. Each column is a pandas Series and can have its own data type; all columns share the data frame’s index. section 2.0
Table 2.1 Country data (view table figure)
A country table makes the column role concrete: Country, Area, and Population each describe a different attribute across the same records. section 2.0
Work with columns by selecting them, calculating from them, and storing derived values:
- Select one column with df['column_name']; the result is a Series. section 2.0
- Use arithmetic between columns when their Series share an index; the result is another Series with that index. section 2.6
- Create or replace a column by assigning a Series, NumPy array, or list of matching length. section 2.6
- Use assign to add columns while returning a new data frame, which supports readable method chains. section 2.6
Derive tax-planning columns
Given product prices and sales, first store current net income, then calculate the results after proposed tax rates: df['current_net'] = (df['retail_price'] - df['wholesale_price']) * df['sales'] df['after_15'] = df['current_net'] * 0.85 df['after_20'] = df['current_net'] * 0.80 df['after_25'] = df['current_net'] * 0.75 df[['current_net', 'after_15', 'after_20', 'after_25']] The derived columns preserve the data frame’s row structure and can be selected together for comparison. section 2.5 section 2.6








