Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/python-3.x/17.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/django/24.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 3.x 熊猫:使用单独数据框中一个单元格的值填充数据框列中的所有行_Python 3.x_Pandas_Csv_Analysis - Fatal编程技术网

Python 3.x 熊猫:使用单独数据框中一个单元格的值填充数据框列中的所有行

Python 3.x 熊猫:使用单独数据框中一个单元格的值填充数据框列中的所有行,python-3.x,pandas,csv,analysis,Python 3.x,Pandas,Csv,Analysis,我想用单独数据框中一个单元格的值填充dataframe列中的所有行 两个dfs都基于从同一CSV读取的数据 data_description = pd.read_csv(file.csv, nrows=1) #this two rows of data: one row of column headers and one row of values. The value I want to use later is under the header "average duratio

我想用单独数据框中一个单元格的值填充dataframe列中的所有行

两个dfs都基于从同一CSV读取的数据

data_description = pd.read_csv(file.csv, nrows=1) 

#this two rows of data: one row of column headers and one row of values. The value I want to use later is under the header "average duration"

data_table = pd.read_csv(file.csv, skiprows=3) 

#this is a multi row data table located directly below the description. I to want add a "duration" column will all rows populated by "average duration" from above.

df1 = pd.DataFrame(data_description)
df2 = pd.DataFram(data_table)

df2['duration'] = df1['average duration']
最后一行仅适用于列中的第一个from。如何向下延伸所有行


如果我直接分配“平均持续时间”值,它会工作,例如,
df2['duration']=60
,但我希望它是动态的。

您必须从df1中提取值,然后将值分配给df2。分配的是一个系列,而不是值

data_description = pd.read_csv(file.csv, nrows=1) 

data_table = pd.read_csv(file.csv, skiprows=3) 

df1 = pd.DataFrame(data_description)
df2 = pd.DataFram(data_table)

df2['duration'] = df1['average duration'][0]

我怀疑这会很简单。谢谢