Open Draymonders opened 4 years ago
import pandas as pd
df = pd.DataFrame([[1,2,3],[4,5,6]], columns=["a", "b", "c"])
df = pd.read_csv("SalesJan2009.csv")
iloc
= integer-location
是以行号列号名字来的
同numpy
的索引,只不过需要加上iloc属性df.iloc[1,:]
结果
Transaction_date 2001/2/9 4:53
Product Product1
Price 1200
Payment_Type Visa
Name Betina
City Parkville
State MO
Country United States
Account_Created 2001/2/9 4:42
Last_Login 2001/2/9 7:49
Latitude 39.195
Longitude -94.6819
Name: 1, dtype: object
loc
则是以kv
方式来存的
df.loc[1,['Price', 'Product']]
结果
Price 1200
Product Product1
Name: 1, dtype: object
df["Price"]
or df.Price
大多数操作都同numpy
一样
df["Price2"] = df.Price
df.append({"Price": 1})
然后查看df
会发现新增了一行,除了Price
列为1
,其余都是NaN
df3 = df1.append(df2, ignore_index=True)
select Price from df where Price > 1200
df.Price = df.Price.astype(int)
df[df.Price>1200]
select Country from df like 'Aus%'
df.loc[df.Country.str.startswith("Aus")]
order by 功能
df.sort_values('Price')
df.sort_values('Price', ascending=False)
df.sort_values(["Price, "City"], ascending=[True, False])
group by功能
df.Price
是pandas.core.series.Series
类型str
的方法
startswith
endswith
contains
upper
lower
find
split
strip
replace
slice
match
extract
pandas入门