Add A New Column
title: "Add a New Column"
author: "Rj"
date: 2019-04-20
description: "List Test"
type: technical_note
draft: false
data = {
'city' : ['Toronto', 'Montreal', 'Waterloo'],
'points' : [80, 70, 90]
}
{'city': ['Toronto', 'Montreal', 'Waterloo'], 'points': [80, 70, 90]}
|
city |
points |
| 0 |
Toronto |
80 |
| 1 |
Montreal |
70 |
| 2 |
Waterloo |
90 |
df = df.assign(code = [1, 2, 3])
|
city |
points |
code |
| 0 |
Toronto |
80 |
1 |
| 1 |
Montreal |
70 |
2 |
| 2 |
Waterloo |
90 |
3 |
Score: 10
Advanced-Custom-Lambda
title: "Advanced Custom Lambda"
author: "Rj"
date: 2019-04-22
description: "-"
type: technical_note
draft: false
import numpy as np
import pandas as pd
# Check the student passed either math or passed at least in 2 subjects. If no condidition matched, consider them as failed
def pass_math_or_two_subjects(row):
if(row.maths > 34):
return …
Read More
Apply Custom Function
title: "Apply Custom Function"
author: "Rj"
date: 2019-04-20
description: "List Test"
type: technical_note
draft: false
data = {
'city' : ['Toronto', 'Montreal', 'Waterloo'],
'points' : [80, 70, 90]
}
{'city': ['Toronto', 'Montreal', 'Waterloo'], 'points': [80, 70, 90]}
Read More
Apply Function-2933
title: "Apply Function"
author: "Rj"
date: 2019-04-20
description: "List Test"
type: technical_note
draft: false
data = {
'city' : ['Toronto', 'Montreal', 'Waterloo', 'Toronto', 'Waterloo', 'Toronto', 'Toronto'],
'points' : [80, 70, 90, 85, 79, 82, 200]
}
{'city': ['Toronto',
'Montreal',
'Waterloo',
'Toronto',
'Waterloo',
'Toronto',
'Toronto'],
'points': [80, 70, 90, 85, 79 …
Read More
Astype 2
title: "Astype 2"
author: "Rj"
date: 2019-04-24
description: "-"
type: technical_note
draft: false
import numpy as np
import pandas as pd
marks = [
[90, 87],
[90, 95],
[92, 95]
]
[[90, 87], [90, 95], [92, 95]]
df = pd.DataFrame(marks, columns=['maths', 'science'])
Read More
Categorical To Numerical
title: "Categorial to Numerical"
author: "Rj"
date: 2019-04-24
description: "-"
type: technical_note
draft: false
import numpy as np
import pandas as pd
data = {
'sam' : ['archery', 'badminton', 'athletics', 'cycling_road', 'canoe_sprint', 'boxing'],
'medal' : ['gold', 'silver', 'bronze', 'gold', 'gold', 'silver']
}
Read More
Csv-To-Dataframe
title: "CSV to Dataframe"
author: "Rj"
date: 2019-04-22
description: "-"
type: technical_note
draft: false
import numpy as np
import pandas as pd
csv = pd.DataFrame.from_csv('uk-500.csv')
/Users/rajacsp/anaconda3/envs/py36/lib/python3.6/site-packages/ipykernel_launcher.py:1: FutureWarning: from_csv is deprecated. Please use read_csv(...) instead. Note that …
Read More
Custom-Function-As-Lambda
title: "Custom Function as Lambda"
author: "Rj"
date: 2019-04-22
description: "-"
type: technical_note
draft: false
import numpy as np
import pandas as pd
def apply_math_special(row):
return (row.maths *2 + (row.language/2) + (row.history/3) + (row.science/4))
df = pd.read_csv('abc.csv')
Read More