Pandas not reading correct column
Question:
Here is my code:
uploaded_file = st.file_uploader("Choose a file")
if uploaded_file:
st.session_state.uploaded_file = uploaded_file
try:
dataframe = pd.read_csv(st.session_state.uploaded_file, delimiter=';')
st.write(dataframe.head())
st.session_state.dataframe = dataframe
except pd.errors.ParserError:
st.write("Feil in file reading")
Here is how it should be (importing csv in excel):
Correct
Here is how it is importing using my code:
Wrong columns
Here is a snippet from my csv-file:
csv-file
I have tried encoding, names for easch columns and etc.
Answers:
Your header has 17 entries but your data has 18 entries.
If you add an additional column to your header entries you should be able to load your dataset.
For example add ;unknown
to the end of the header line.
KasseJournalId;Tidspunkt;Hendelse;OrgenhetId;ArbeidstasjonNr;Brukernavn;Fornavn;Etternavn;KasseEkspNr;NyVerdi;ForrigeVerdi;TotalBelop;KasseOppgjorNr;BilagNr;TerminalRapportId;EventCode;KasseJournalRapportId;unknown
Here is my code:
uploaded_file = st.file_uploader("Choose a file")
if uploaded_file:
st.session_state.uploaded_file = uploaded_file
try:
dataframe = pd.read_csv(st.session_state.uploaded_file, delimiter=';')
st.write(dataframe.head())
st.session_state.dataframe = dataframe
except pd.errors.ParserError:
st.write("Feil in file reading")
Here is how it should be (importing csv in excel):
Correct
Here is how it is importing using my code:
Wrong columns
Here is a snippet from my csv-file:
csv-file
I have tried encoding, names for easch columns and etc.
Your header has 17 entries but your data has 18 entries.
If you add an additional column to your header entries you should be able to load your dataset.
For example add ;unknown
to the end of the header line.
KasseJournalId;Tidspunkt;Hendelse;OrgenhetId;ArbeidstasjonNr;Brukernavn;Fornavn;Etternavn;KasseEkspNr;NyVerdi;ForrigeVerdi;TotalBelop;KasseOppgjorNr;BilagNr;TerminalRapportId;EventCode;KasseJournalRapportId;unknown