大量のデータは、重複データが今、パンダによって列を見つける必要があり、処理し、その後にエクセルに保存されているため、Excelで保存されたブラックリストデータ:今日は、主に次のような問題を解決します。
numpyのはツールであり、データ分析タスクを解決するためのツールは、次の2つの主要なデータ構造クラスに基づいて作成されたパンダ:
DATAFRAME:Excelのテーブルpandas.core.frame.DataFrameと同様に、テーブルとして理解することができる
シリーズ:これは、単一の列を表します。データフレームは、複数の列、すなわち、複数のシリーズが含まれ、各シリーズには名前が付いています。pandas.core.series.Series
データ・タイプ(DTYPE)パンダは、サポートされている:
1.フロート(のfloat64)
2.整数(Int64型、UInt64型)
3. BOOL
4 datetime64 [NS](2013年1月2日)
5 datetime64 [NS、TZ]を
6。 timedelta [NS]
7カテゴリ
8.オブジェクト(文字列)は
、デフォルトのデータ型がInt64型である、のfloat64
以下は、元のExcelファイルであります
各列のシリーズのデータ・タイプのファイルを表示するには
import pandas as pd
# 更改数据类型
def change_data_type():
print(excel_df.dtypes)
if __name__ == '__main__':
excel_df = pd.read_excel('E:\zenglingwei\\test\\5.xlsx')
change_data_type()
私たちは、blacklistValueのデフォルトがint型であり、私たちは、これらの列のデータ型を変換する必要があるので、我々は、IDカード18、いくつかのエクセルの後ろに保存されたときに再び0になると知っていました。2つのアイデアがあり、一つは変換エクセル、変換後の別の読書を読んでいます。
まず、すべての読みがたりDTYPE =「str」は、文字列、DTYPE =「オブジェクト」に変換しました
import pandas as pd
# 更改数据类型
def change_data_type():
print(excel_df.dtypes)
if __name__ == '__main__':
excel_df = pd.read_excel('E:\zenglingwei\\test\\5.xlsx',dtype='object') # dtype='str'
change_data_type()
第二に、指定された列は、文字列、オブジェクトまたは読んSTRに変換され、
# 更改数据类型
def change_data_type():
print(excel_df.dtypes)
if __name__ == '__main__':
excel_df = pd.read_excel('E:\zenglingwei\\test\\5.xlsx',dtype = {'blacklistValue' : object,'priority':str}) # dtype='str'
change_data_type()
読み取りが文字列に変換された後、第三に、:astype(STR)、astypeを使用していない(オブジェクト) - > Excelに格納されるか、またはint型とき。
import pandas as pd
# 更改数据类型
def change_data_type():
excel_df[['blacklistValue','priority']] = excel_df[['blacklistValue','priority']].astype(str)
print(excel_df.dtypes)
excel_df.to_excel('excel_to_python.xls',sheet_name='sheet', index=False)
if __name__ == '__main__':
excel_df = pd.read_excel('E:\zenglingwei\\test\\5.xlsx') # dtype='str'
change_data_type()