Python Forum
Outputs "NaN" after "DataFrame columns" function?
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Outputs "NaN" after "DataFrame columns" function?
#1
import numpy as np
import pandas as pd
import matplotlib.pyplot as plt
from scipy.signal import argrelextrema

data = pd.read_csv("Data/EURUSD60.csv", delimiter="\t")

print(data)

data = pd.DataFrame(data=data, columns=["Date", "Open", "High", "Low", "Close", "Volume"])

print(data)
and output is:
[Image: JpNHRj.png]

I'm trying some strategies and calculations on prices. Previously I was working on windows (I was using excel for the python file) then I installed manjaro and encountered such problem with the csv file.
Reply
#2
NaN is missing data or None (can be used interchangeably).
Reply
#3
(Jan-23-2021, 10:53 PM)Larz60+ Wrote: NaN is missing data or None (can be used interchangeably).

Yes I know, but why ? :)As you can see in the picture, when there is data after the first "read_csv", NaN returns after naming the columns.
Reply
#4
First change line 10 to:
df = pd.DataFrame(data=data, columns=["Date", "Open", "High", "Low", "Close", "Volume"])
you were overwriting 'data'.

Then, to isolate the data, please change line 8 to:
print(f"\nCSV data:\n{data}")

and line 12 to:
print(f"\ndataframe:\n{df}")

Show results again
epsilon likes this post
Reply
#5
(Jan-24-2021, 06:35 PM)Larz60+ Wrote: First change line 10 to:
df = pd.DataFrame(data=data, columns=["Date", "Open", "High", "Low", "Close", "Volume"])
you were overwriting 'data'.

Then, to isolate the data, please change line 8 to:
print(f"\nCSV data:\n{data}")

and line 12 to:
print(f"\ndataframe:\n{df}")

Show results again

import numpy as np
import pandas as pd
import matplotlib.pyplot as plt
from scipy.signal import argrelextrema

data = pd.read_csv("Data/EURUSD60.csv", delimiter="\t")

print(f"\nCSV data:\n{data}")

df = pd.DataFrame(data=data, columns=["Date", "Open", "High", "Low", "Close", "Volume"])

print(f"\ndataframe:\n{df}")
I did, but the result is the same as in the picture
Reply
#6
The new output should contain the two print statements, which will isolate the output to the different sections of software. That was what I was interested in seeing.

If you don't see the print statements, something else is happening here.
Reply
#7
Looking at the screenshot, note that initial data dataframe does not have these columns. Confirmed by 99 rows x6 columns (index is 0 to 98)
index 0 is 2012-12-14 18:00, and the column names are values for 2012-12-24 17:00

I guess your csv file has no header and you need to specify columns when reading it.
Can you show your file (e.g. top 10 rows of it?)

or try
data = pd.read_csv("Data/EURUSD60.csv", delimiter="\t", names=["Date", "Open", "High", "Low", "Close", "Volume"])
epsilon likes this post
If you can't explain it to a six year old, you don't understand it yourself, Albert Einstein
How to Ask Questions The Smart Way: link and another link
Create MCV example
Debug small programs

Reply
#8
(Jan-26-2021, 07:19 PM)buran Wrote: Looking at the screenshot, note that initial data dataframe does not have these columns. Confirmed by 99 rows x6 columns (index is 0 to 98)
index 0 is 2012-12-14 18:00, and the column names are values for 2012-12-24 17:00

I guess your csv file has no header and you need to specify columns when reading it.
Can you show your file (e.g. top 10 rows of it?)

or try
data = pd.read_csv("Data/EURUSD60.csv", delimiter="\t", names=["Date", "Open", "High", "Low", "Close", "Volume"])

Yes, there is no title in the csv-file, as you said, I added a header(name=[..]) in "read_csv" and it's okay.
Thanks!
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Convert several columns to int in dataframe Krayna 2 678 May-21-2021, 08:55 AM
Last Post: Krayna
  Adapting a dataframe to the some of columns flyway 2 956 Aug-12-2020, 07:21 AM
Last Post: flyway
  A function to return only certain columns with certain string illmattic 2 1,017 Jul-24-2020, 12:57 PM
Last Post: illmattic
  Difference of two columns in Pandas dataframe zinho 2 1,619 Jun-17-2020, 03:36 PM
Last Post: zinho
  DataFrame: To print a column value which is not null out of 5 columns mani 2 1,070 Mar-18-2020, 06:07 AM
Last Post: mani
Question Dividing a single column of dataframe into multiple columns based on char length darpInd 2 1,065 Mar-14-2020, 09:19 AM
Last Post: scidam
  Interate for loop over certain columns in dataframe Finpyth 2 1,022 Mar-06-2020, 08:34 AM
Last Post: Finpyth
  How to highlight dataframe columns SriRajesh 1 1,054 Feb-28-2020, 11:02 PM
Last Post: Marbelous
  Does the order of columns in the DataFrame matter? new_to_python 11 2,586 Feb-17-2020, 12:32 AM
Last Post: scidam
  Filter value from DataFrame apply a function and save to xlsx zinho 1 1,108 Dec-22-2019, 03:54 PM
Last Post: zinho

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020