1. 程式人生 > >pandas 將DataFrame轉化成dict

pandas 將DataFrame轉化成dict

直接轉換就行了,key為DataFrame的column;

import pandas as pd

data = pd.read_csv('./input/month_6_1.csv')
print(data.head())
data_dict = dict(data)
# print(data_dict)
print(data_dict.keys())

print(type(data_dict['province']))

結果:

[5 rows x 11 columns]
dict_keys(['province', 'city', 'address', 'longitude', 'latitude', 'price', 'buildingTypeId', 'tradeTypeId', 'listingDate', 'daysOnMarket', 'bedrooms'])
<class 'pandas.core.series.Series'>

Process finished with exit code 0