In [1]:
import pandas as pd
import numpy as np
In [2]:
df = pd.read_csv('data/src/sample_header.csv')
print(df)
In [3]:
print(np.sqrt(df))
In [4]:
print(np.amax(df))
In [5]:
print(np.mean(df, axis=1))
In [6]:
print(df.max())
In [7]:
print(df.max(axis=1))
In [8]:
s = df['a']
print(s)
In [9]:
f_brackets = lambda x: '[{}]'.format(x)
print(s.map(f_brackets))
In [10]:
def f_str(x):
return str(x).replace('1', 'One').replace('2', 'Two').replace('3', 'Three').replace('4', 'Four')
print(s.map(f_str))
In [11]:
f_oddeven = lambda x: 'odd' if x % 2 == 1 else 'even'
print(df.applymap(f_oddeven))
In [12]:
f_maxmin = lambda x: max(x) - min(x)
print(df.apply(f_maxmin))
In [13]:
print(df.apply(f_maxmin, axis=1))
In [14]:
df['b'] = df['b'].map(f_str)
print(df)
In [15]:
df.iloc[2] = df.iloc[2].map(f_str)
print(df)