Instructions
Objective
Write a program to implement pandas dataframe in python language.
Requirements and Specifications
Description
- Write a Python assignment program that reads the CSV file into a Panda dataframe. Using that dataframe, print the row, source IP, and destination IP as a table.
- Write a python program that reads the CSV file into an ArrayList. Convert the ArrayList to a string array and print the row, source IP, and destination IP on the same line using a loop. Place your screenshots and responses in a Microsoft Word document. Be sure to include the .python files with your code for the python portions.
Source Code
import pandas as pd
import csv
if __name__ == '__main__':
# Open file
data = list()
with open('IN300_Dataset1.csv', 'r') as f:
lines = f.readlines()
for i, line in enumerate(lines):
# ignore first line
if i == 0:
continue
# Remove all quotation marks
#line = line.replace('"', '')
line = line.strip()
# Now, split
cells = line.split(',"')
sublist = []
for cell in cells:
cell = cell.replace('"', '')
sublist.append(cell)
data.append(sublist)
# Finally, convert this list of rows into a dataframe
df = pd.DataFrame(data, columns = ['No.', 'Time', 'Source', 'Destination', 'Protocol', 'Length', 'Info'])
# Finally, get No. Source and Destination into a new dataframe and print
df2 = df[['No.', 'Source', 'Destination']]
print(df2.head())
Related Samples
At ProgrammingHomeworkHelp.com, we offer an extensive collection of Python assignment samples to assist students in mastering their coursework. Our samples cover a wide range of topics, including data analysis, web development, machine learning, and more. Each sample is meticulously crafted by our experts to ensure clarity and accuracy, providing a valuable resource for students seeking guidance. Whether you're struggling with a specific concept or need help with an entire project, our Python assignment samples are designed to support your academic success.
Python
Python
Python
Python
Python
Python
Python
Python
Python
Python
Python
Python
Python
Python
Python
Python
Python
Python
Python
Python