讀取csv格式的資料集
讀取excel資料集pd.dataframe.from_csv(
"csv_file"
)pd.read_csv(
"csv_file"
)
將dataframe直接寫入csv檔案pd.read_excel(
"excel_file"
)
基本的資料集特徵資訊df.to_csv(
"data.csv"
, sep=
",", index=
false
)
基本的資料集統計資訊df.info(
)
將 dataframe 列印成**的樣子df.describe(
)
列出所有列的名字(tabulate(print_table, headers=headers)
)
df.colums
刪除缺失資料
替換缺失資料df.fropna(axis=
0, how=
'any'
)
檢查空值 nandf.replace(to_replace=
none
, value=
none
)
刪除特徵pd.isnull(
object
)
將目標型別轉換為浮點型df.drop(
'feature_variable_name'
, axis=1)
axis=
1表示列
axis=
0表示行
將dataframe轉換為numpy陣列pd.to_numeric(df[
"feature_name"
], error=
'coerce'
)
取 dataframe 的前面「n」行df.as_matrix(
)
df.head(n)
通過特徵名取資料
df.loc[feature_name]
對 dataframe 使用函式]
重新命名行def
multiply
(x):
return x*
2df[
"height"].
(multiply)
子dataframedf.rename(columns =
, inplace=
true
)
總結資料new_df = df[
["name"
,"size"
]]
排序df.
sum(
)df.
min(
)df.
max(
)df.idxmin(
)df.idxmax(
)df.mean(
)df.median(
)df.corr(
)df[
"size"
].median(
)
布林型索引df.sort_values(ascending=
false
)
按行、列取值df[df[
"size"]==
5]
df.loc([0
],['size'
])
Pandas的拼接操作
import numpy as np from pandas import dataframe,series import pandas as pd 0回顧numpy的級聯 練習 1.生成2個3 3的矩陣,對其分別進行兩個維度上的級聯 nd np.random.randint 0,10,size 3...
Pandas的簡單操作
1.建立 用列表建立 pd.series 1 2,3 4,5 用numpy陣列建立 a np.array 1 2,3 4,5 pd.series a 用字典建立 dict s pd.series dict s 也可通過其他series定義新的series物件 arr np.array 1 2,3 4...
pandas的基本操作
資料讀寫 讀入mysql資料庫資料 匯入第三方模組 import pymysql 連線mysql資料庫 conn pymysql.connect host localhost user root password test database test port 3306 charset utf8 讀...