英文:
Assign column to dataframe with different lengths
问题
df = pd.read_excel('//client/Y$/Risikomanagement/Flussvermessung/ALD/Profile/Tabelle/QP_Aare_267234_269910_022019.xlsx', header=5)
value_flussname = (pd.read_excel('//client/Y$/Risikomanagement/Flussvermessung/ALD/Profile/Tabelle/QP_Aare_267234_269910_022019.xlsx', skiprows=0, nrows=1, header=None))
value_flussname = value_flussname.drop(columns=[0,2,3,4,5,6,7,8,9])
value_flussname = value_flussname.values[0]
df = df.assign(Flussname = value_flussname)
英文:
I have a single column and single row pandas dataframe ("valueFlussname") that I want to assign to all the rows in a different dataframe (df) that is 1802 rows x 10 columns.
df = df.assign(Flussname = value_flussname)
gives me a "Length of values does not match length of index".
How can I assign the value in the "valueFlussname" dataframe to all the rows of the "df" dataframe in a new Column named "Flussname"?
df = pd.read_excel('//client/Y$/Risikomanagement/Flussvermessung/ALD/Profile/Tabelle/QP_Aare_267234_269910_022019.xlsx', header=5)
value_flussname = (pd.read_excel('//client/Y$/Risikomanagement/Flussvermessung/ALD/Profile/Tabelle/QP_Aare_267234_269910_022019.xlsx', skiprows = 0, nrows = 1, header = None))
value_flussname = value_flussname.drop(columns=[0,2,3,4,5,6,7,8,9])
value_flussname = value_flussname.values[0]
df = df.assign(Flussname = value_flussname)
Thank you,
Davide
答案1
得分: 1
尝试:
df = df.assign(Flussname = valueFlussname.values[0][0])
使用 valueFlussname
你的数据框。
英文:
Try :
df = df.assign(Flussname = valueFlussname.values[0][0])
With valueFlussname
your dataframe.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论