英文:
Why am I getting error when using 'squeeze' keyword in dataframe constructor?
问题
使用关键字 squeeze 将一个单列数据框转换为 Series 时,出现错误 TypeError: read_csv() got an unexpected keyword argument 'squeeze'。
期望得到一个 Series。
英文:
alcohol = pd.read_csv('https://andybek.com/pandas-drinks', usecols=['country','wine_servings'], index_col='country', squeeze=True)
when using the keyword squeeze to convert a one columned dataframe to series getting an error TypeError: read_csv() got an unexpected keyword argument 'squeeze'.
expecting a series
答案1
得分: 1
read_csv不再有squeeze参数。它在Pandas 2.0中被移除。
从read_csv()中删除了参数..., squeeze, ... (..., GH43427)。
在读取CSV后,改用DataFrame.squeeze('columns')。
英文:
read_csv no longer has a squeeze parameter. It was removed in Pandas 2.0.
> - Removed arguments ..., squeeze, ... from [read_csv()](https://pandas.pydata.org/docs/reference/api/pandas.read_csv.html#pandas.read_csv "pandas.read_csv") (..., GH43427)
Instead use DataFrame.squeeze('columns') after reading the CSV.
答案2
得分: 0
read_csv()函数中的squeeze参数在pandas库中不可用。squeeze参数在其他pandas函数中使用,例如DataFrame.squeeze()或Series.squeeze(),用于将具有单个列或轴的DataFrame或Series转换为Series。
import pandas as pd
alcohol = pd.read_csv('https://andybek.com/pandas-drinks', usecols=['country', 'wine_servings'], index_col='country')
alcohol = alcohol['wine_servings'].squeeze()
英文:
The squeeze parameter in the read_csv() function is not available in the pandas library. The squeeze parameter is used in other pandas functions such as DataFrame.squeeze() or Series.squeeze() to convert a DataFrame or Series with a single column or axis into a Series.
import pandas as pd
alcohol = pd.read_csv('https://andybek.com/pandas-drinks', usecols=['country', 'wine_servings'], index_col='country')
alcohol = alcohol['wine_servings'].squeeze()
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。


评论