一种选择是
ast.literal_eval用作转换器:
>>> import ast>>> df = pd.read_clipboard(header=None, quotechar='"', sep=',', ... converters={1:ast.literal_eval})>>> df 0 10 HK [5328.1, 5329.3, 2013-12-27 13:58:57.973614]1 HK [5328.1, 5329.3, 2013-12-27 13:58:59.237387]2 HK [5328.1, 5329.3, 2013-12-27 13:59:00.346325]
并根据需要将这些列表转换为Dataframe,例如:
>>> df = pd.Dataframe.from_records(df[1].tolist(), index=df[0],... columns=list('ABC')).reset_index()>>> df['C'] = pd.to_datetime(df['C'])>>> df 0 A B C0 HK 5328.1 5329.3 2013-12-27 13:58:57.9736141 HK 5328.1 5329.3 2013-12-27 13:58:59.2373872 HK 5328.1 5329.3 2013-12-27 13:59:00.346325
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)