简体   繁体   中英

list object has no attribute split error for csv file

Please help me understand what is wrong with my code, I simply can't figure it out

with open("floo.csv", 'r') as infile:
    reader = csv.reader(infile, delimiter=",")
    with open('departments_upd.csv','w',newline='') as csvout:
        writer = csv.writer(csvout)
        for row in reader:
            df = row.split(".")
            bleep = df[1] + '.' + df[0] + '.' + df[2]
            writer.writerow(row)
return bleep

Can you give an example of the 'row' variable? Basically, it is saying that you can not use the 'split' method on a variable of type 'list'. If it is a list of index 1, you could just convert it to a string and then use the split method by adding a line:

row_str = row[0]

and then using the split method

use pandas: example:

covid_training_data = pd.read_csv("covidTrain.csv")

I am kind of curious what this project is tbh

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM