I am trying to import my data from excel in to python using Pandas. I then want to plot the data. At the moment I am struggling with blank values in my data. Source data looks like attached image. When I run the code as below the data printed contains 'Nan'
import pandas as pd
df = pd.read_excel('CSTRS Chem Eng Practicals_2.xlsx', sheet_name='Flow Rates')
df = pd.DataFrame(df)
df = df.values
Time2 = df[4:,0]
Conc1 = df[4:,2]
Conc2 = df[4:,4]
Conc3 = df[4:,6]
Conc4 = df[4:,8]
Conc5 = df[4:,10]
print (Time2)
print (Conc1)
If I use df.notna() then I get this error message 'AttributeError: 'numpy.ndarray' object has no attribute 'notna'' Can anyone suggest a way to remove the NaN values so I am able to plot the data
Thanks
I have tried df.notna() and I have also tried slicing the data and neither works
I am trying to import my data from excel in to python using Pandas. I then want to plot the data. At the moment I am struggling with blank values in my data. Source data looks like attached image. When I run the code as below the data printed contains 'Nan'
import pandas as pd
df = pd.read_excel('CSTRS Chem Eng Practicals_2.xlsx', sheet_name='Flow Rates')
df = pd.DataFrame(df)
df = df.values
Time2 = df[4:,0]
Conc1 = df[4:,2]
Conc2 = df[4:,4]
Conc3 = df[4:,6]
Conc4 = df[4:,8]
Conc5 = df[4:,10]
print (Time2)
print (Conc1)
If I use df.notna() then I get this error message 'AttributeError: 'numpy.ndarray' object has no attribute 'notna'' Can anyone suggest a way to remove the NaN values so I am able to plot the data
Thanks
I have tried df.notna() and I have also tried slicing the data and neither works
Share Improve this question edited Feb 17 at 15:04 mozway 262k13 gold badges49 silver badges96 bronze badges asked Feb 17 at 15:04 Jess CrowJess Crow 211 bronze badge New contributor Jess Crow is a new contributor to this site. Take care in asking for clarification, commenting, and answering. Check out our Code of Conduct. 5 |1 Answer
Reset to default 0I can't test since I don't have the Excel file but the following code should works:
import pandas as pd
df = (
pd.read_excel('CSTRS Chem Eng Practicals_2.xlsx', sheet_name='Flow Rates')
.dropna()
)
df = df.values
? Just don't do that and it should be fine – mozway Commented Feb 17 at 15:05df = pd.DataFrame(df)
is also useless. – mozway Commented Feb 17 at 15:05