forked from spandey1296/Learn-Share-Hacktoberfest2021
-
Notifications
You must be signed in to change notification settings - Fork 0
/
dietrecommendation.py
76 lines (52 loc) ยท 1.9 KB
/
dietrecommendation.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
# -*- coding: utf-8 -*-
"""DietRecommendation.ipynb
Automatically generated by Colaboratory.
Original file is located at
https://colab.research.google.com/drive/14NgZYKZB6K9PXXJgU2k5RGppQIlsuBTv
"""
# Commented out IPython magic to ensure Python compatibility.
#Importing the standard libraries for data manipulation and analysis
import numpy as np
import pandas as pd
#Importing the plotting and visualization library for the mathematical and numerical analysis
import seaborn as sns
import matplotlib.pyplot as plt
# %matplotlib inline
#%matplotlib inline sets the backend of matplotlib to the inline backend that displays outputs of plotting commands.
import io
import warnings
warnings.filterwarnings("ignore") #To ignore any warning
from google.colab import files
uploaded = files.upload()
for fn in uploaded.keys():
print('User uploaded file "{name}" with length {length} bytes'.format(
name=fn, length=len(uploaded[fn])))
import io
data = pd.read_csv(io.BytesIO(uploaded['abbrev.csv'])) #reading data
data.head()
data.columns
data.shape
data.isna().sum
data=data.filter(['shrt_desc','potassium_mg'])
data
data.isnull().sum()
data = data.dropna(axis=0)
data
data.isnull().sum()
data.describe
# create a list of our conditions
conditions = [
(data['potassium_mg'] < 2000/7.16846),
(data['potassium_mg'] > 2000/7.16846) & (data['potassium_mg'] <= 2600/7.16846),
(data['potassium_mg'] > 2600/7.16846) & (data['potassium_mg'] < 3500/7.16846),
]
# create a list of the values we want to assign for each condition
values = ['0','1','2']
# create a new column and use np.select to assign values to it using our lists as arguments
data['zone_attribute'] = np.select(conditions, values)
# display updated DataFrame
data.head(20)
#data['zone_attribute'] = data.apply(lambda data:zone_attribute(data).axis=1)
data['zone_attribute'].value_counts()
data['zone_attribute']=0
data.head()