![](/img/trans.png)
[英]Pandas dataframe created from json has unnamed column - can't insert into MySQL due to unnamed column issue
[英]Can't insert column into a newly created dataframe (Python - Pandas)
設df為 dataframe。 我正在嘗試將列a放入另一個名為df2的 dataframe
df2.insert(1,'a',df['a'])
從 excel 加載 df2 時一切順利:
df2 = pandas.read_excel(filepath)
然而,當我從頭開始創建 df2 時,出現了一個錯誤:
df2 = pandas.DataFrame
錯誤內容如下:
insert() missing 1 required positional argument: 'value'
到底是怎么回事?
正確的方法是你現在在pd.DataFrame(abc)
中給出一個值,這里abc
可以是矩陣或字典
你也可以使用它:
pd.DataFrame(df[['a']])
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.