1 year ago
#379740
nahammond
Identifying column for data in a csv fille in a Python dataframe statement
I have tried many things to create a Python dataframe from 4 variables on a csv file: Date (mm/dd/yyyy format), floating point variables Reserves, FF, IORB. All tries result in error message that I haven't identified column with the data (apologies if my terminology is not correct). I found some easy errors to fix. Now from a df.columns, the name of my df is rates, I see the correct data names Date, Reserves, FF, IORB. I even renamed the dataframe 'rates' names. But statements with these names are errors, that the variable isn't defined. This is first time I've imported a CSV file into Python
from datetime import datetime
import matplotlib.pyplot as plt
import numpy as np
import pandas as pd
import dateparser
d= lambda x: pd.datetime.strptime(x, '%m/%w/%Y')
dateparse = lambda x: d(x)
rates = pd.read_csv(r'C:/Users/Owner/Documents/Research/SOMA/SomaFinal.csv','./data.txt', index_col=[0],\ usecols=[0,1,2,3],skiprows=6, parse_dates=['Date']))
print(rates.columns)
rates.info()
rates = rates.rename(columns={'rates[1]': 'Reserves', 'rates[2]': 'FF', 'rates[3]': 'IORB'})
print(FF)
**ERROR: File "C:\Users\Owner\Documents\Research\SOMA\soma.py", line 27, in print(FF) NameError: name 'FF' is not defined
Output:
Index(['Date', 'WRESBAL', 'FF', 'IORB'], dtype='object')
<class 'pandas.core.frame.DataFrame'>
RangeIndex: 1999 entries, 0 to 1998
Data columns (total 4 columns):
# Column Non-Null Count Dtype
--- ------ -------------- -----
0 Date 1992 non-null datetime64[ns]
1 WRESBAL 1992 non-null float64
2 FF 1992 non-null float64
3 IORB 39 non-null object
dtypes: datetime64[ns](1), float64(2), object(1)
memory usage: 62.6+ KB
6
<class 'pandas.core.frame.DataFrame'>
RangeIndex: 2005 entries, 0 to 2004
python
dataframe
date
names
0 Answers
Your Answer