将不同长度的列分配给数据框

huangapple go评论76阅读模式
英文:

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.

huangapple
  • 本文由 发表于 2023年6月5日 21:50:13
  • 转载请务必保留本文链接:https://go.coder-hub.com/76407107.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定