您可能遇到了dtype问题 . 以下代码适用于我:
import pandas as pd
data = {'working_hr': {3: 9.0}, 'order_no': {3: 731231}}
df = pd.DataFrame.from_dict(data, dtype=object)
然后:
>>> df.loc[3, 'order_no'] = [1, 2]
>>> df
order_no working_hr
3 [1, 2] 9
注意 dtype=object . 这可能是您缩短DataFrame时错误消失的原因,特别是如果您(例如)浮点数为_64577 . 因此,请检查您的混合类型列是否确实设置为dtype object .
同样适用于您提供的CSV:
>>> df = pandas.read_clipboard(sep='\t', index_col=0)
>>> df
buyer order_no item smv
0 H&M 992754 Cole tank top 6.17
1 H&M 859901 Thilo Bottom 8.55
2 H&M 731231 Palma Short Sleeve Tee 5.65
3 H&M 731231/339260 Palma Price Tee 5.65
4 H&M 859901/304141 Thilo Paijama Set top/Elva Tank Top 5.80/5.58
5 H&M 768380 Folke Tank Top 6
6 H&M 596701/590691 Paul Rock Tee 7.65
7 H&M/Mexx 731231/KIEZ-P002 Palma Short Sleeve Tee/Shorts 5.65/12.85
8 NaN NaN NaN NaN
9 Ginatricot 512008/512009 J.Tank top 4.6
>>> df.loc[3, 'order_no'] = str(df.loc[3, 'order_no']).split('/')
>>> df
buyer order_no item smv
0 H&M 992754 Cole tank top 6.17
1 H&M 859901 Thilo Bottom 8.55
2 H&M 731231 Palma Short Sleeve Tee 5.65
3 H&M [731231, 339260] Palma Price Tee 5.65
4 H&M 859901/304141 Thilo Paijama Set top/Elva Tank Top 5.80/5.58
5 H&M 768380 Folke Tank Top 6
6 H&M 596701/590691 Paul Rock Tee 7.65
7 H&M/Mexx 731231/KIEZ-P002 Palma Short Sleeve Tee/Shorts 5.65/12.85
8 NaN NaN NaN NaN
9 Ginatricot 512008/512009 J.Tank top 4.6