如何仅提取此 table 中列的数字部分? (Python)

How to extract only the numerical part of the columns in this table? (Python)

我正在 Python 中编辑一个 CSV 文件,我删除了一些列,创建了一个索引并进行了过滤。但我一直无法提取 columas 的数字部分。我怎样才能只从列中提取数字信息?

仅提取列数据的数字部分。示例:

市场时间=11:18:26.549

整个专栏应该是这样的:

11:18:26,549

导入 pandas 作为 pd

df = pd.read_csv('C:/Users/TECNOLOGIA/datos.csv',names=['LocalTime','Message','MarketTime','Symbol','Type', 'Price', 'Size', 'Source','Condition','Tick','Mmid','SubMarketId','Date'] , usecols=['Type','MarketTime','Price'],index_col='Type') df=(df.loc['Type=0']) 打印 (df)

调整在 pandas applying regex to replace values 给出的 Regex/Pandas StringMethods 答案,你将得到类似这样的东西:

import pandas as pd

df = pd.DataFrame(['MarketTime=11:18:28.792','MarketTime=11:18:28.792'], columns=['MarketTime'])

df['MarketTime'] = df['MarketTime'].str.extract(r'([\d:,.]+)')
print(df)