import pandas as pd
import xlsxwriter
import openpyxl as px
import numpy as np
from xlwt import Workbook
from os.path import expanduser
home = expanduser("~")
def read_survey():
df_appliance=pd.read_csv('C:/Users/nidi/Desktop/New folder/app_info.csv')
df_appliance.fillna(0, inplace=True)
return df_appliance
df_appliance=read_survey()
def map_appliance_info(df_appliance):
oven_usage=[]
#oven_type_radio=[]
oven_type_micro=[]
oven_type_oven=[]
tube_light_count=[]
led_count=[]
incand_count=[]
cfl_count=[]
for i in range(len(df_appliance['sur_key'].values)):
if df_appliance['oven-type'].values[i]=='radio':
#oven_type_radio.append(1)
oven_type_micro.append(0)
oven_type_oven.append(0)
elif df_appliance['oven-type'].values[i]=='micro':
#oven_type_radio.append(0)
oven_type_micro.append(1)
oven_type_oven.append(0)
elif df_appliance['oven-type'].values[i]=='oven':
#oven_type_radio.append(0)
oven_type_micro.append(0)
oven_type_oven.append(1)
else:
#oven_type_radio.append(0)
oven_type_micro.append(0)
oven_type_oven.append(0)
if df_appliance['oven-ousg'].values[i]=='little':
oven_usage.append(1)
elif df_appliance['oven-ousg'].values[i]=='defrost':
oven_usage.append(5)
elif df_appliance['oven-ousg'].values[i]=='mod':
oven_usage.append(12)
elif df_appliance['oven-ousg'].values[i]=='ext':
oven_usage.append(30)
else:
oven_usage.append(0)
#return df_appliance_mapped
df_appliance_mapped = map_appliance_info(df_appliance)
result=np.array(df_appliance_mapped)
This is my code. when printing map_appliance_info(df_appliance) i am getting the error-
File "E:/iisc/code/try.py", line 69, in map_appliance_info df_appliance_mapped = map_appliance_info(df_appliance)
File "E:/iisc/code/try.py", line 35, in map_appliance_info for i in range(len(df_appliance['sur_key'].values)):
File "C:\\Users\\nidi\\Anaconda2\\lib\\site-packages\\pandas\\core\\frame.py", line 1957, in getitem indexer = convert_to_index_sliceable(self, key)
File "C:\\Users\\nidi\\Anaconda2\\lib\\site-packages\\pandas\\core\\indexing.py", line 1658, in convert_to_index_sliceable elif isinstance(key, compat.string_types):
RuntimeError: maximum recursion depth exceeded while calling a Python object
can anybody help. Thanks
Since you are calling pd.read_excel
, you must have Pandas installed. Therefore the easiest way to merge the data is to call pd.merge
on two DataFrames:
import pandas as pd
df1 = pd.DataFrame({0: [1, 1, 0, 0], 1: [0, 0, 1, 1], 2: [1, 2, 1, 5], 3: [1, 2, 3, 4]})
df2 = pd.DataFrame({0: [0, 1, 1, 0], 1: [1, 0, 0, 1], 2: [1, 2, 1, 5]})
result = pd.merge(df2, df1, on=[0,1,2])
print(result.values)
prints
[[0 1 1 3]
[1 0 2 2]
[1 0 1 1]
[0 1 5 4]]
If df_appliance_mapped
is the second DataFrame, you could use:
first_df = pd.read_excel('E:/iisc/code/energy_usage_appliance.xlsx',0,header=None)
result = pd.merge(df_appliance_mapped, first_df, on=[0,1,2])
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.