'AttributeError python how i solve [closed]
**Hi i have this code with python which choose three column(Time", "Node", "DelayS), with condition among the conditions in the Type column choose just "LastDelay" when I executed i have this problem " AttributeError: 'DataFrame' object has no attribute 'Type'"" How I can solve this problem???? I tried many solutions but it doesn't work And thank you in advance **
import pandas
import csv
import pandas as pd
file = 'delayintersection.txt'
table = pandas.read_csv(file, delimiter='\t')
table2 = table[(table.Type == "LastDelay")]
table29 = table2[["Time", "Node", "DelayS"]]
table29.to_csv("./delay.csv", index=False)
############################# Node 29##############################
file = open('delay.csv')
csvreader = csv.reader(file)
rows = []
for row in csvreader:
if ("29" in row):
rows.append(row)
# name of csv file
filename = "finalresultsdelay29.csv"
# field names
fields = ['Time', 'Node', 'DelayS']
# writing to csv file
with open(filename, 'w') as csvfile:
# creating a csv writer object
csvwriter = csv.writer(csvfile)
# writing the fields
csvwriter.writerow(fields)
# writing the data rows
csvwriter.writerows(rows)
df = pd.read_csv("finalresultsdelay29.csv")
# checking the number of empty rows in th csv file
print(df.isnull().sum())
# Droping the empty rows
modifiedDF = df.dropna()
modifiedDF.to_csv('finalresultsdelay29.csv', index=False)
############################# Node 39##############################
file = open('delay.csv')
csvreader = csv.reader(file)
rows = []
for row in csvreader:
if ("39" in row):
rows.append(row)
# name of csv file
filename = "finalresultsdelay39.csv"
# field names
fields = ['Time', 'Node', 'DelayS']
# writing to csv file
with open(filename, 'w') as csvfile:
# creating a csv writer object
csvwriter = csv.writer(csvfile)
# writing the fields
csvwriter.writerow(fields)
# writing the data rows
csvwriter.writerows(rows)
df = pd.read_csv("finalresultsdelay39.csv")
# checking the number of empty rows in th csv file
print(df.isnull().sum())
# Droping the empty rows
modifiedDF = df.dropna()
modifiedDF.to_csv('finalresultsdelay39.csv', index=False)
#############################Node 84 #################################
file = open('delay.csv')
csvreader = csv.reader(file)
rows = []
for row in csvreader:
if ("84" in row):
rows.append(row)
# name of csv file
filename = "finalresultsdelay84.csv"
# field names
fields = ['Time', 'Node', 'DelayS']
# writing to csv file
with open(filename, 'w') as csvfile:
# creating a csv writer object
csvwriter = csv.writer(csvfile)
# writing the fields
csvwriter.writerow(fields)
# writing the data rows
csvwriter.writerows(rows)
df = pd.read_csv("finalresultsdelay84.csv")
# checking the number of empty rows in th csv file
print(df.isnull().sum())
# Droping the empty rows
modifiedDF = df.dropna()
modifiedDF.to_csv('finalresultsdelay84.csv', index=False)

Solution 1:[1]
Try writing it out like table['Type'] instead.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | vtasca |
