1
data_df = pandas.read_csv('details.csv')
data_df = data_df.replace('Null', np.nan)
df = data_df.groupby(['country', 'branch']).count()
df = df.drop('sales', axis=1)
df = df.reset_index()
print df
我想結果轉換成數據幀(DF )來,我下面提到的用戶定義的JSON格式。打印結果(DF)後,我會得到結果的形式如何大熊貓數據幀結果轉換爲用戶定義的JSON格式
country branch no_of_employee total_salary count_DOB count_email
x a 30 2500000 20 25
x b 20 350000 15 20
y c 30 4500000 30 30
z d 40 5500000 40 40
z e 10 1000000 10 10
z f 15 1500000 15 15
我想將其轉換爲Json.My所需的格式是
x
{
a
{
no.of employees:30
total salary:2500000
count_email:25
}
b
{
no.of employees:20
total salary:350000
count_email:25
}
}
y
{
c
{
no.of employees:30
total salary:4500000
count_email:30
}
}
z
{
d
{
no.of employees:40
total salary:550000
count_email:40
}
e
{
no.of employees:10
total salary:100000
count_email:15
}
f
{
no.of employees:15
total salary:1500000
count_email:15
}
}
請注意,我不不想在以JSON數據幀結果的所有字段(如:count_DOB)
同時運行此代碼我有類型錯誤:to_dict()得到了一個意想不到的關鍵字參數「東方」 –
它不與該樣品與實際數據打交道? – jezrael
抱歉它did'nt工作 –