[英]I am having a problem printing off the content of a column that in a file
I have read a column from a CSV file that contains temperatures. 我已经从CSV文件中读取了包含温度的列。 They print off fine but there is the letter C after each number.
他们打印得很好,但每个数字后面都有字母C。 I want to print off only the numbers from the column.
我只想打印列中的数字。 I would appreciate any help I can get with that.
我将不胜感激。
import csv
with open('Data.csv', 'r') as csv_file:
csv_reader = csv.reader(csv_file)
next(csv_reader)
for line in csv_reader:
print(line[1])
You can remove a character from a string using the str.replace
method. 您可以使用
str.replace
方法从字符串中删除字符。
import csv
with open('Data.csv', 'r') as csv_file:
csv_reader = csv.reader(csv_file)
next(csv_reader)
for line in csv_reader:
print(line[1].replace("C", "")) # Replaces "C" with ""
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.