我已经走了这么远。当我运行它时,它会将字符串数字转换为浮点数,甚至为我摆脱了时间戳。那我该如何将这些数字放入新的组中?我的目标是,我希望每行成为自己的列表,但仅包含时间戳和每行的最后0之间的数字。
import pandas as pd
import numpy as np
ver = '''
2018.12.0400:00,0.73572,0.73614,0.73544,0.73550,520,0
2018.12.0401:00,0.73550,0.73594,0.73545,0.73553,1181,0
2018.12.0402:00,0.73553,0.73606,0.73510,0.73539,1960,0
2018.12.0403:00,0.73539,0.73621,0.73481,0.73608,2898,0
'''
number = ver.split(',')
for num in number:
try:
new = float(num)
print(new)
except:
print('this one messed up')
答案 0 :(得分:0)
您可以先按行拆分数据,然后再按','。
"myText"
输出:
ver = '''2018.12.0400:00,0.73572,0.73614,0.73544,0.73550,520,0
2018.12.0401:00,0.73550,0.73594,0.73545,0.73553,1181,0
2018.12.0402:00,0.73553,0.73606,0.73510,0.73539,1960,0
2018.12.0403:00,0.73539,0.73621,0.73481,0.73608,2898,0'''
ver = [i.split(',') for i in ver.split('\n')]
df = pd.DataFrame(ver)
df