如何从CSV文件提取指定数值并写入Pandas DataFrame?
Extract Specific Values from CSV Comments into Pandas DataFrame
I have a Pandas DataFrame containing a column named path. I can iterate over these paths using the following code:
for i, p in enumerate(df['path']):
My goal is to extract a specific numerical value from each CSV file referenced by these paths and write that value back into the DataFrame. Each CSV file uses a comment-based format like this:
some valuessome values : some valuessome values : some valuessome values : some valuessome string : the value I wantsome string : some values
I believe regular expressions are the right tool for this task, but I'm unsure about the exact syntax to use. I have a template code snippet to build from:
if re.match(r"something", p): df = pd.read_csv(p) df.iloc[i, value_column] = the value I want
Can someone provide a feasible implementation solution for this?
内容的提问来源于stack exchange,提问作者Allentro
相关产品推荐
相关产品推荐

