pandas 为什么在'read_csv'中使用'squeeze'关键字时会出现错误?

kxxlusnw  于 12个月前  发布在  其他
关注(0)|答案(2)|浏览(758)
alcohol = pd.read_csv('https://andybek.com/pandas-drinks', usecols=['country','wine_servings'], index_col='country', squeeze=True)

当使用关键字squeeze将一列的字符串转换为序列时,我得到一个错误TypeError: read_csv() got an unexpected keyword argument 'squeeze'

f45qwnt8

f45qwnt81#

read_csv不再有squeeze参数。它在Pandas 2.0中被删除。

  • 已删除参数...,squeeze,...从read_csv()(...,GH43427

在阅读CSV后使用DataFrame.squeeze('columns')

zy1mlcev

zy1mlcev2#

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()

相关问题