import pandas as pd
import numpy as np
from datetime import datetime
data1 = pd.read_csv("合并数据.csv",encoding='gbk')#utf8无法解决乱码,只能用gbk
data2 = pd.read_csv("租赁户清单.csv",encoding='gbk')
data2
dict1 = data1['摘要']
dict1 = dict1.to_dict()
custmers = list(np.array(data2['客户名称']))
def changeone(x):
for index, value in dict1.items():
if x in str(value):
data1['标记'] = x
else:
data1['标记'] = "无"
for i in range(len(custmers)):
changeone(custmers[i])
data1
print(data2.iat[0,0])#注意这是元素定位方法
嘉可胜
for i in range(len(data2)):
data1['标记'] = data1['标记'].apply(lambda x: x if data1['摘要'].str.contains(x,na = False) else 0)
NameError: name 'data2' is not defined
data.dropna(how='all')#删除全为空值的行,不全为空值的行不会删除
data_ni.rename(index={"Shipped on": "Shipped date"},inplace=True)
/opt/venv/lib/python3.7/site-packages/pandas/core/frame.py:4133: SettingWithCopyWarning:
A value is trying to be set on a copy of a slice from a DataFrame
See the caveats in the documentation: https://pandas.pydata.org/pandas-docs/stable/user_guide/indexing.html#returning-a-view-versus-a-copy
errors=errors,
data_ni['Shipped on'].replace('nan','01-03-2019')
data_ni.head()
data_ni.sort_values(by=['TransactionDate'],ascending=False)
data_ni['period'].apply(lambda x : ('TransactionDate','Shipped date'))
KeyError: 'period'
data_ni.drop(index=[417])
data_ni
#pearsonr(data_ni['销售金额'],data_ni['实收金额'])
data_ni['销售金额']
data_ni1=data_ni[['销售金额','实收金额']].fillna(0)
pearsonr(data_ni1['销售金额'],data_ni1['实收金额'])
[[0 for _ in range(5)] for _ in range(7)]