Pandas的常用操作

import numpy as np
import pandas as pd
from pandas import Series, DataFrame

#转化
sdata = {"Ohio": 35000, "Texas": 71000, "Oregon": 16000, "Utah": 5000}
obj3 = pd.Series(sdata)
obj3.to_dict()
obj3.to_numpy()
# 判空
states = ["California", "Ohio", "Oregon", "Texas"]
obj4 = pd.Series(sdata, index=states)
pd.isna(obj4)
pd.notna(obj4)

data = {"state": ["Ohio", "Ohio", "Ohio", "Nevada", "Nevada", "Nevada"],
        "year": [2000, 2001, 2002, 2001, 2002, 2003],
        "pop": [1.5, 1.7, 3.6, 2.4, 2.9, 3.2]}
frame = pd.DataFrame(data)
# 取行
frame.loc[1]
frame.iloc[2]
# 删除
frame["eastern"] = frame["state"] == "Ohio"
del frame["eastern"]


labels = pd.Index(np.arange(3))
obj = pd.Series([1.5, -2.5, 0], index=labels)
obj.index is labels


你可能感兴趣的:(Python,python)