簡體   English   中英

使用Pandas中的Series連接DataFrame

[英]concat a DataFrame with a Series in Pandas

有人可以解釋這個pandas concat代碼有什么問題嗎,為什么數據框仍然是空的?我正在使用anaconda distibution,據我記得它以前工作過。 在此輸入圖像描述

您想使用此表單:

result = pd.concat([dataframe, series], axis=1)

pd.concat(...)不會“原位”發生到原始dataframe但它會返回連接結果,因此您需要在某處分配連接,例如:

>>> import pandas as pd
>>> s = pd.Series([1,2,3])
>>> df = pd.DataFrame()
>>> df = pd.concat([df, s], axis=1)  # We assign the result back into df
>>> df
   0
0  1
1  2
2  3

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM