我有以下dictionary
和dataframe
cust_dict = {'ABC': Empty DataFrame
Columns: [Date, Particulars, Vch No., Outwards, Amount]
Index: [], 'BCD': Empty DataFrame
Columns: [Date, Particulars, Vch No., Outwards, Amount]
Index: []}
df
Date Particulars Vch Type
0 2017-04-01 00:00:00 ABC Sales
1 2017-04-06 00:00:00 BCD Sales
1 2017-04-05 00:00:00 ABC Sales
我试图从df
获取'ABC'
作为key
,从dictionary
中提取dataframe
,并将日期添加到dictionary
嵌套dataframe
中的Date
列中。我试过.at
,append
,assign
for index, row in df.iterrows():
print(row['Particulars'])
cust_name = row['Particulars']
cust_dict[cust_name] = cust_dict[cust_name]['Date'].append(date)
cust_dict[cust_name].at['Date'] = row['Date']
# A lot of variations of .at
if cust_name == 'ABC':
code = 4
cust_dict[cust_name]['Particulars'] = code
elif cust_name == 'BCD:
code = 5
cust_dict[cust_name]['Particulars'] = code
我不知道该怎么做,或者这根本不可能
df
将有多行,particulars
列将有一个公司说ABC
4-5次或更多次
预期产出:
cust_dict['ABC']
Date Particulars Vch Type
0 2017-04-01 00:00:00 4 Sales
1 2017-04-05 00:00:00 4 Sales
短暂性脑缺血发作
这是通过字典理解的一种方法
如下所示,我建议您使用字典来映射细节,而不是
if
/elif
构造相关问题 更多 >
编程相关推荐