我有这样的数据(来自jq)
script_runtime{application="app1",runtime="1651394161"} 1651394161
folder_put_time{application="app1",runtime="1651394161"} 22
folder_get_time{application="app1",runtime="1651394161"} 128.544
folder_ls_time{application="app1",runtime="1651394161"} 3.868
folder_ls_count{application="app1",runtime="1651394161"} 5046dataframe应该允许对每一行进行操作:
script_runtime,app1,1651394161,1651394161
folder_put_time,app1,1651394161,22它在文本文件中。我怎样才能轻松地将它加载到熊猫中进行数据处理呢?
发布于 2022-05-03 05:45:24
df = pd.read_csv("textfile.txt", header=None, delimiter=r"\s+")df['function'] = df[0].str.split("{",expand=True)[0]
df['application'] = df[0].str.split("\"",expand=True)[1]
df['runtime'] = df[0].str.split("\"",expand=True)[3]其结果是数据文件如下所示:

如果要删除包含括号内值的第一列:
df = df.iloc[: , 1:]

完整代码:
df = pd.read_csv("textfile.txt", header=None, delimiter=r"\s+")
df['function'] = df[0].str.split("{",expand=True)[0]
df['application'] = df[0].str.split("\"",expand=True)[1]
df['runtime'] = df[0].str.split("\"",expand=True)[3]
df = df.iloc[: , 1:]https://stackoverflow.com/questions/72094860
复制相似问题