简体   繁体   English

当我向 dataframe 添加新列时,它显示为 NaN

[英]When i add a new column to my dataframe, it shows as NaN

So I needed to add the 'count' value to the dataframe as a new column.所以我需要将“计数”值添加到 dataframe 作为新列。

I used the below code:我使用了以下代码:

count=HC_Pune.groupby('Customer').size()
HC_Pune.sort_values(by='Customer',inplace=True,ascending=True)
BCP.insert(2,'HC',count,True)
BCP.head(2)

This is the output that I get这是我得到的 output

Could someone please help me in clearing this problem as to why I am getting NaN for the data?有人可以帮我解决这个问题,为什么我要为数据获取NaN吗?

From the look of your short output,you passed empty values to count which are in turn passed to your dataframe.从您的短 output 的外观来看,您将空值传递给count ,然后将其传递给您的 dataframe。 Take a look at your dataset.看看你的数据集。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 当我转置 dataframe 时,它显示 nan 值 - when i transpose a dataframe, it shows nan values 当数据框列中有 NaN 时,如何将推文(对象)添加到绘图图表中? - How do I add tweets (objects) to a plotly chart when I have NaN's in the dataframe column? 尝试在Pandas数据框中添加列时,为什么会得到np.NaN值? - Why am I getting np.NaN values when trying to add a column to a Pandas dataframe? 为什么在数据框中创建新列时NaN值显示不正确? - Why NaN values appear incorrectly when creating new column in dataframe? Pandas 将新列添加到现有 DataFrame 时存储 NaN 值 - Pandas storing NaN value when adding new column to existing DataFrame 将新列添加到 pandas DataFrame 时的 NaN 值 - NaN values when new column added to pandas DataFrame 当我使用 DataFrame 输出列时,为什么我的数据输出中的值是 NaN? - Why the values from my data output as NaN when I use DataFrame for outputting a column? Why do I keep getting 'Nan' values when I try to add a column from a csv dataframe to an existing dataframe both opened on pandas? - Why do I keep getting 'Nan' values when I try to add a column from a csv dataframe to an existing dataframe both opened on pandas? nan 出现在我的箱线图上,但没有标有 nan 的列? - nan shows up on my boxplot but there is no column labeled nan? 当我将numpy数组转换为Dataframe时,它将值更新为Nan - When i convert my numpy array to Dataframe it update values to Nan
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM