ASSIGNMENT 3 CCS2-505, Fall 2019 Due: Wednesday, Dec 11th, (23:59) Please read the entire PDF before starting. You must do this assignment individually. It is very important that you follow the...

1 answer below »
Assignment is described in attachements


ASSIGNMENT 3 CCS2-505, Fall 2019 Due: Wednesday, Dec 11th, (23:59) Please read the entire PDF before starting. You must do this assignment individually. It is very important that you follow the directions as closely as possible. The directions, while perhaps tedious, are designed to make it as easy as possible for me to mark the assignments. Up to 30% can be removed for bad indentation of your code as well as omitting comments, or poor coding structure. To get full marks, you must: • Follow all directions below – In particular, make sure that all the file names and column names are spelled exactly as de- scribed in this document. Otherwise, you will receive a 30% penalty. • Make sure that your code run – Code that does not run (e.g due to a NameError, TypeError) will receive a very lowmark. • Write your name and student ID as a comment in all .py files you hand in • Indent your code properly • Name your variables appropriately – The purpose of each variable should be obvious from the name • Comment your work – A comment every line is not needed, but there should be enough comments to fully understand your program 1 Part 1 In this assignment, you will be asked to analyze vehicular mobility trace data on highway. You have been provided with two .csv files: 01 tracks.csv and 01 tracksMeta.csv. Throughout this assignment you are allowed to use everything we have learned in class to solve the questions. You also need to make sure to precisely follow the instructions provided. Question 1: Fill missing value (5 points) The 01 tracks.csv has few missing x and y values as shown as below. Both x and y are the coordinate value, where the x-value represents the horizontal position and the y-value represents the vertical position. Please fill the missing value via linear interpolation and output the result.csv. Page 2 Question 2: Vehicle direction (10 points) Besides the x and y value, the 01 tracks.csv also contains vehicle id and time frame. Note that each time frame is about 0.04 second. Suppose we have two lane marking: upper lane marking and lower lane marking. The upper lane marking has 3 values: 8.51;12.59;16.43 and the lower lane marking has 3 values: 21.00;24.96;28.80. These values are represented as the line position in terms of the y-axis from bottom to top direction (See the figure below). Your task is to add an extra column to result.csv called ’direction’. If a vehicle’s y value is inside the range 8.51 - 16.43, the direction is 1, and 0 if the value is in between 21.0 - 28.80. Outliers might exist, vehicles might have weird y value such as 7.3. In such case, we label direction according to the closest lane markings. For example, 7.3 is close to 8.51, so the direction should be 1. Question 3: x velocity and y velocity (10 points) In this part, you need to calculate two velocity values: x velocity and y velocity for each vehicle (Different ID). Thus you need to store these two values under two new columns: ’x velocity’ and ’y velocity’ into your result.csv. Since a time unit for a frame is 0.04 seconds and given two x values: 362.26 and 363.73, the x velocity is calculated as: x velocity = (363.73 − 362.26)/0.04 Same trick should be applied for calculating the y velocity. Note that for the first x value, since we do not have previous x value, the velocity should be 0. Please see below for an example output. Page 3 Question 4: Surrounding vehicles (10 points) In this part, you need to calculate the number of surrounding vehicles given a distance as the threshold. To do this, you need to first group the data base on the time frame. For example, assume the time frame 4 has 4 vehicles: id = [1, 3, 27, 41]. Then, we divide these vehicles into two sets according to the vehicles’ direction. Finally, calculate the distance between each vehicles within the set. Given the x and y value, the distance should be calculated by the following function: distance = √ (x2 − x1)2 + (y2 − y1)2 Thus, let 50 and 100 be the distance threshold. You should display the number of neighbor vehicles that the distance is under or equal to the threshold by creating two columns: ’neighbor 50’ and ’neighbor 100’. For example, given the threshold is 50, if the distance between vehicle id 3 and 27 is 20 at frame 4, then neighbor 50 for id 3 and id 27 at frame 4 should both +1. Below shows the sample output to the result.csv. Question 5: Merge data (5 points) In this question, you are asked to merge the 01 tracksMeta.csv to result.csv according to the vehicle id. The 01 tracksMeta.csv contains width and height of each vehicle, thus your result.csv should also has these two columns. Question 6: Number of lane changes (10 points) In this question, you are asked to count number of lane changes of each vehicle using the upper lane marking and the lower lane marking. Note that lane changes happened when the vehicle across the middle line. Below is the sample output to the result.csv Page 4 Part 2 In this part of your assignment, you will be asked to draw several graphs using Matplotlib. For each question, you will be provided with a sample output. Note that these outputs are just for template use, you are free to make them prettier. Question 7: vehicle class distribution (5 points) In this question, you need to draw a pie chart for vehicle class distribution. We categorize vehicles into three classes according to vehicles’ width. For width that is less than 4.7 is a car, for width that is between 4.7 and 6.7 is a van and for width that is larger than 6.7 is a truck. Below is a sample graph. Note that you should show me three vehicle classes. Question 8: Vehicle velocity distribution (5 points) In this question, you need to draw a plot which shows vehicle velocity distribution for both x and y. Below is a sample plot for x velocity, you should show both x and y on the same plot. Page 5 Question 9: Vehicle velocity by lanes (10 points) In this question, you need to draw a plot which shows only vehicle x velocity for four different lanes. By using the upper lane marking and the lower lane marking, we can find the four lanes. e.g. lane 0 is between 8.51 to 12.59, lane 1 is between 12.59 to 16.43, and so on. Outliers should not be in any of the lanes in this case. Below is a sample plot. Question 10: Vehicle position (10 points) In this question you are going to draw a plot showing a vehicle’s position. Since each vehicle can switch between two lanes while moving, you should show the position with two different color according to the two different lanes. Warping your code into a function called position(id). The function is taking an ID as a parameter. Thus, if we call the position(25), we should get the following example output. Page 6 Question 11: Vehicle position with neighbor (20 points) In this question, you need to show not only a vehicle’s positions but also show the neighbor information. You need to write a function called neighbors(*id) which takes multiple ID as an inputs. For all input vehicles, they must have at least 50 overlay time frames. You should depict each vehicle with different color. However, if the vehicle is close to the other vehicle within 50 meters as the threshold (hint: the neighbor 50 column), you should change the mark color to red. Please see the following example for two vehicles. What To Submit Please put all your files in a folder called Assignment3. Zip the folder (DO NOT RAR it or use other compression extension like .7z) and submit it on MyCourses. If you use other compression extension like .rar, .7z etc, you will lose marks. Use only .zip. Inside your zipped folder, there must be the following files. Do not submit any other files Any deviation from these requirements may lead to lost marks. a3 part1.py a3 part2.py 01 tracks.csv 01 tracksMeta.csv result.csv All plots .png In your result.csv, plase make sure you have the following headers: id, x, y, frame, direction, x velocity, y velocity, neighbor 50, neighbor 100, width, height, and lane changes Page 7
Answered Same DayDec 10, 2021CCS2

Answer To: ASSIGNMENT 3 CCS2-505, Fall 2019 Due: Wednesday, Dec 11th, (23:59) Please read the entire PDF before...

Kshitij answered on Dec 12 2021
144 Votes
assignment.rar
Untitled69.ipynb
{
"cells": [
{
"cell_type": "code",
"execution_count": 1,
"metadata": {},
"outputs": [],
"source": [
"import pandas as pd"
]
},
{
"cell_type": "code",
"execution_count": 2,
"metadata": {},
"outputs": [
{
"data": {
"text/html": [
"
\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"
Unnamed: 0idxyframe
001362.2621.681
111363.7321.682
221365.2721.683
331366.8321.684
441368.4221.685
\n",
"
"
],
"text/plain": [
" Unnamed: 0 id x y frame\n",
"0 0 1 362.26 21.68 1\n",
"1 1 1 363.73 21.68 2\n",
"2 2 1 365.27 21.68 3\n",
"3 3 1 366.83 21.68 4\n",
"4 4 1 368.42 21.68 5"
]
},
"execution_count": 2,
"metadata": {},
"outp
ut_type": "execute_result"
}
],
"source": [
"df = pd.read_csv('01tracks.csv')\n",
"df.head()"
]
},
{
"cell_type": "code",
"execution_count": 3,
"metadata": {},
"outputs": [],
"source": [
"df = df.interpolate(method='linear', limit_direction='forward', axis=0)"
]
},
{
"cell_type": "code",
"execution_count": 4,
"metadata": {},
"outputs": [],
"source": [
"df.to_csv('result.csv') "
]
},
{
"cell_type": "code",
"execution_count": 5,
"metadata": {},
"outputs": [],
"source": [
"mylist = [16.43, 21.00]"
]
},
{
"cell_type": "code",
"execution_count": 6,
"metadata": {},
"outputs": [],
"source": [
"import statistics\n",
"number = statistics.median(mylist)"
]
},
{
"cell_type": "code",
"execution_count": 7,
"metadata": {},
"outputs": [],
"source": [
"df['direction'] = [1 if x <= number else 0 for x in df['y']] "
]
},
{
"cell_type": "code",
"execution_count": 8,
"metadata": {},
"outputs": [
{
"data": {
"text/html": [
"
\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"
Unnamed: 0idxyframedirection
001362.2621.6810
111363.7321.6820
221365.2721.6830
331366.8321.6840
441368.4221.6850
\n",
"
"
],
"text/plain": [
" Unnamed: 0 id x y frame direction\n",
"0 0 1 362.26 21.68 1 0\n",
"1 1 1 363.73 21.68 2 0\n",
"2 2 1 365.27 21.68 3 0\n",
"3 3 1 366.83 21.68 4 0\n",
"4 4 1 368.42 21.68 5 0"
]
},
"execution_count": 8,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"df.head()"
]
},
{
"cell_type": "code",
"execution_count": 9,
"metadata": {},
"outputs": [],
"source": [
"l1 = [0]\n",
"l2 = [0]\n",
"for i in range (1, len(df)):\n",
" l1.append((df['x'][i]-df['x'][i-1])/0.04)\n",
" l2.append((df['y'][i]-df['y'][i-1])/0.04)\n",
"df['x_velocity'] = l1\n",
"df['y_velocity'] = l2"
]
},
{
"cell_type": "code",
"execution_count": 10,
"metadata": {},
"outputs": [
{
"data": {
"text/html": [
"
\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"
Unnamed: 0idxyframedirectionx_velocityy_velocity
001362.2621.68100.000.0
111363.7321.682036.750.0
221365.2721.683038.500.0
331366.8321.684039.000.0
441368.4221.685039.750.0
\n",
"
"
],
"text/plain": [
" Unnamed: 0 id x y frame direction x_velocity y_velocity\n",
"0 0 1 362.26 21.68 1 0 0.00 0.0\n",
"1 1 1 363.73 21.68 2 0 36.75 0.0\n",
"2 2 1 365.27 21.68 3 0 38.50 0.0\n",
"3 3 1 366.83 21.68 4 0 39.00 0.0\n",
"4 4 1 368.42 21.68 5 0 39.75 0.0"
]
},
"execution_count": 10,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"df.head()"
]
},
{
"cell_type": "code",
"execution_count": 11,
"metadata": {},
"outputs": [],
"source": [
"group = df.groupby('frame')\n",
"df2 = group.apply(lambda x: x['id'].unique())"
]
},
{
"cell_type": "code",
"execution_count": 12,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"frame\n",
"1 [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12]\n",
"2 [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14]\n",
"3 [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14]\n",
"4 [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14]\n",
"5 [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14]\n",
"6 [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14]\n",
"7 [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14]\n",
"8 [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14]\n",
"9 [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14]\n",
"10 [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14]\n",
"dtype: object"
]
},
"execution_count": 12,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"df2[:10]"
]
},
{
"cell_type": "code",
"execution_count": 14,
"metadata": {},
"outputs": [],
"source": [
"import numpy as np\n",
"df['neighbor_50']= np.zeros(len(df))\n",
"df['neighbor_100'] = np.zeros(len(df))"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"for i in range(0, len(df2)):\n",
" for j in range(0, len(df2[i])):\n",
" if df.loc[(df['id']==df2[i][j]) & (df['direction']==0)] :\n",
" \n",
" df['neighbor_50'][i] = df['neighbor_50'][i] + 1\n",
" df[['x','y']].loc[df['id']==df2[i][j]]"
]
},
{
"cell_type": "code",
"execution_count": 15,
"metadata": {},
"outputs": [
{
"data": {
"text/html": [
"
\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"
Unnamed: 0idwidthheight
0014.852.12
1124.241.92
2233.941.92
3345.052.22
4454.241.82
\n",
"
"
],
"text/plain": [
" Unnamed: 0 id width height\n",
"0 0 1 4.85 2.12\n",
"1 1 2 4.24 1.92\n",
"2 2 3 3.94 1.92\n",
"3 3 4 5.05 2.22\n",
"4 4 5 4.24 1.82"
]
},
"execution_count": 15,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"df3 = pd.read_csv('01tracksmeta.csv')\n",
"df3.head()"
]
},
{
"cell_type": "code",
"execution_count": 16,
"metadata": {},
"outputs": [],
"source": [
"df = pd.merge(df, df3[['width','height','id']], on='id')"
]
},
{
"cell_type": "code",
"execution_count": 17,
"metadata": {},
"outputs": [
{
"data": {
"text/html": [
"
\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"
Unnamed: 0idxyframedirectionx_velocityy_velocityneighbor_50neighbor_100widthheight
001362.2621.68100.000.00.00.04.852.12
111363.7321.682036.750.00.00.04.852.12
221365.2721.683038.500.00.00.04.852.12
331366.8321.684039.000.00.00.04.852.12
441368.4221.685039.750.00.00.04.852.12
\n",
"
"
],
"text/plain": [
" Unnamed: 0 id x y frame direction x_velocity y_velocity \\\n",
"0 0 1 362.26 21.68 1 0 0.00 0.0 \n",
"1 1 1 363.73 21.68 2 0 36.75 0.0 \n",
"2 2 1 365.27 21.68 3 0 38.50 0.0 \n",
"3 3 1 366.83 21.68 4 0 39.00 0.0 \n",
"4 4 1 368.42 21.68 5 0 39.75 0.0 \n",
"\n",
" neighbor_50 neighbor_100 width height \n",
"0 0.0 0.0 4.85 2.12 \n",
"1 0.0 0.0 4.85 2.12 \n",
"2 0.0 0.0 4.85 2.12 \n",
"3 0.0 0.0 4.85 2.12 \n",
"4 0.0 0.0 4.85 2.12 "
]
},
"execution_count": 17,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"df.head()"
]
},
{
"cell_type": "code",
"execution_count": 18,
"metadata": {},
"outputs": [],
"source": [
"lol = []"
]
},
{
"cell_type": "code",
"execution_count": 19,
"metadata": {},
"outputs": [],
"source": [
"df.loc[(df['y'] >= 8.51) & (df['y'] < 12.59), 'lane'] = 0\n",
"df.loc[(df['y'] >= 12.59) & (df['y'] < 16.43), 'lane'] = 1\n",
"df.loc[(df['y'] >= 21.00) & (df['y'] < 24.96), 'lane'] = 2\n",
"df.loc[(df['y'] >= 24.96) & (df['y'] <= 28.80), 'lane'] = 3"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"print(((df['lane'][df['id'][] == 30]).diff() != 0).sum(axis=0))"
]
},
{
"cell_type": "code",
"execution_count": 20,
"metadata": {},
"outputs": [],
"source": [
"x = 0\n",
"lol.append(x)\n",
"for i in range(1, len(df)):\n",
" x = x + ((df['lane'][i]- df['lane'][i-1] != 0).sum(axis=0))\n",
" lol.append(x)\n",
" if (((df['id'][i]- df['id'][i-1] != 0).sum(axis=0) ) == 1):\n",
" x = 0"
]
},
{
"cell_type": "code",
"execution_count": 21,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"348750"
]
},
"execution_count": 21,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"len(lol)"
]
},
{
"cell_type": "code",
"execution_count": 22,
"metadata": {},
"outputs": [],
"source": [
"df['lane_changes'] = lol"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"df4['id'] = list(range(1, (len(uq_id)+1)))\n",
"df = pd.merge(df, df4, on='id')"
]
},
{
"cell_type": "code",
"execution_count": 38,
"metadata": {},
"outputs": [
{
"data": {
"text/html": [
"
\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"
Unnamed: 0idxyframedirectionx_velocityy_velocityneighbor_50neighbor_100widthheightlane_changesvehicle
001362.2621.68100.000.00.00.04.852.120Van
111363.7321.682036.750.00.00.04.852.120Van
221365.2721.683038.500.00.00.04.852.120Van
331366.8321.684039.000.00.00.04.852.120Van
441368.4221.685039.750.00.00.04.852.120Van
\n",
"
"
],
"text/plain": [
" Unnamed: 0 id x y frame direction x_velocity y_velocity \\\n",
"0 0 1 362.26 21.68 1 0 0.00 0.0 \n",
"1 1 1 363.73 21.68 2 0 36.75 0.0 \n",
"2 2 1 365.27 21.68 3 0 38.50 0.0 \n",
"3 3 1 366.83 21.68 4 0 39.00 0.0 \n",
"4 4 1 368.42 21.68 5 0 39.75 0.0 \n",
"\n",
" neighbor_50 neighbor_100 width height lane_changes vehicle \n",
"0 0.0 0.0 4.85 2.12 0 Van \n",
"1 0.0 0.0 4.85 2.12 0 Van \n",
"2 0.0 0.0 4.85 2.12 0 Van \n",
"3 0.0 0.0 4.85 2.12 0 Van \n",
"4 0.0 0.0 4.85 2.12 0 Van "
]
},
"execution_count": 38,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"data = df.copy()\n",
"data = data.drop(['lane'], axis=1)\n",
"data.head()"
]
},
{
"cell_type": "code",
"execution_count": 39,
"metadata": {},
"outputs": [],
"source": [
"data.to_csv('result.csv')"
]
},
{
"cell_type": "code",
"execution_count": 24,
"metadata": {},
"outputs": [],
"source": [
"df.loc[(df['width'] <= 4.7) , 'vehicle'] = 'Car' \n",
"df.loc[(df['width'] > 4.7) & (df['width'] <= 6.7), 'vehicle'] = 'Van' \n",
"df.loc[(df['width'] > 6.7) , 'vehicle'] = 'Truck' "
]
},
{
"cell_type": "code",
"execution_count": 25,
"metadata": {},
"outputs": [],
"source": [
"from collections import * \n",
"import matplotlib.pyplot as plt\n",
"col_count = Counter(df['vehicle']) \n",
"col_count.keys\n",
"\n",
"class OrderedCounter(Counter, OrderedDict):\n",
" pass\n",
"\n",
"counterlist = OrderedCounter(col_count)\n",
"\n",
"values = counterlist.values()\n",
"keys = counterlist.keys()"
]
},
{
"cell_type": "code",
"execution_count": 26,
"metadata": {},
"outputs": [
{
"data": {
"image/png":...
SOLUTION.PDF

Answer To This Question Is Available To Download

Related Questions & Answers

More Questions »

Submit New Assignment

Copy and Paste Your Assignment Here