简体   繁体   中英

Split single column in csv files using python

This is the data inside one of a column in CSV file.

91.1 [69.6-118.8]
93.9 [74.5-118.3]
96.7 [79.1-118.2]
99.5 [83.8-118.5]
102.3 [88.1-119.3]
105.0 [92.0-120.6]

What I need to do is split this into two column.

91.1             [69.6-118.8]
93.9             [74.5-118.3]
96.7             [79.1-118.2]
99.5             [83.8-118.5]
102.3            [88.1-119.3]
105.0            [92.0-120.6]

The simplest way is to use open.readlines() and str.split()

arr =[]

lines = open("my.csv").readlines()

for line in lines:
    arr.append(line.split())

print(arr)

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