Alteryx Designer Desktop Discussions

Find answers, ask questions, and share expertise about Alteryx Designer Desktop and Intelligence Suite.
SOLVED

Key error

Dhananjay_Galphat1
7 - Meteor

i wrote the below code and converted into dataframe also but getting key error 1

df = (Invoice_No,Date,Lot_No,Expiry_Date,Date_of_Manufacturing,Ethicon_General_PO,Extras)
df = pd.DataFrame(df)
columns = ['INVOICE','DATE','LOT_NO', 'EXPIRY_DATE','DATE_OF_MANUFACTURING','ETHICON_GENERAL_PO','Extras']
df['Name'] = columns

df1 = pd.DataFrame(df)
Alteryx.write(df1,1)

 

please help to resolve this.

Thanks

5 REPLIES 5
seinchyiwoo
Alteryx Alumni (Retired)

Hi,

 

Not quite sure what you're trying to achieve but you might want to debug your code.

I changed the code to below and it works:

 

from ayx import Alteryx

import pandas as pd

df = pd.DataFrame()
columns = ['INVOICE','DATE','LOT_NO', 'EXPIRY_DATE','DATE_OF_MANUFACTURING','ETHICON_GENERAL_PO','Extras']
df['Name'] = columns
Alteryx.write(df,1)

 

seinchyiwoo_0-1601000422540.png

 

 

Dhananjay_Galphat1
7 - Meteor

i am having another column which is coming from the first line (bold one)

 

for line in text.split('\n'):
if line.endswith('Diagnostics'):
Invoice_No = line.split()[0]
Date = line.split()[1]
#Invoice = Invoice_re.search(line)
#if Invoice:
# Invoice_No = Invoice.groups(1)

elif line.startswith('Batch'):
Lot_No = line.split()[-1]

elif line.startswith('Expiry'):
Expiry_Date = line.split()[-1]

elif line.startswith('Manufacturing'):
Date_of_Manufacturing = line.split()[-1]

elif line.startswith('Our Ref.'):
Ethicon_General_PO = line.split()[-1]

elif line.startswith('731670'):
Extras = line.split()[0:10]

df = (Invoice_No,Date,Lot_No,Expiry_Date,Date_of_Manufacturing,Ethicon_General_PO,Extras)
df = pd.DataFrame(df)
columns = ['INVOICE','DATE','LOT_NO', 'EXPIRY_DATE','DATE_OF_MANUFACTURING','ETHICON_GENERAL_PO','Extras']
df['Name'] = columns


df1 = pd.DataFrame(df)
df1

 

 

Alteryx.write(df1,1)

Dhananjay_Galphat1
7 - Meteor

i am getting this output. but Alteryx.write (df,1) is not working for me.

 

Dhananjay_Galphat1_0-1601003225595.png

 

showing Key error:1

seinchyiwoo
Alteryx Alumni (Retired)

You need to assign a column name for your 1st column.

 

Something like below:

 

df = pd.DataFrame()

df['value'] = (Invoice_No,Date,Lot_No,Expiry_Date,Date_of_Manufacturing,Ethicon_General_PO,Extras)

df['Name']= ['INVOICE','DATE','LOT_NO', 'EXPIRY_DATE','DATE_OF_MANUFACTURING','ETHICON_GENERAL_PO','Extras']

 

Alteryx.write(df1,1)

 

Dhananjay_Galphat1
7 - Meteor

Thanks a lot!

 

its working now.

Labels