I need help with this excel to python code

39 views
Skip to first unread message

Shriman Sonti

unread,
Dec 21, 2016, 8:10:14 PM12/21/16
to PyData
I have been working on this code for two days now and i've gotten some good work done, although I just need assistance with this one item.
So my code:
     import glob
import pandas as pd

# get data file names
path =r'C:\Users\spkso\Desktop\in'
filenames = glob.glob(path + "/*.csv")

dfs = []
for filename in filenames:
    csv=pd.read_csv(filename,header=0)
    dfs.append(csv)#,ignore_index=True)

# Concatenate all data into one DataFrame
big_frame = pd.concat(dfs, ignore_index=True)
print (big_frame)

This code when run outputs this:
       Quarterback Quarterback Quaterback Rating
0          NaN          NaN  Andrew Luck    96.5
1          NaN          NaN   Drew Brees    92.4
2          NaN          NaN    Tom Brady    95.2
3          NaN  Andrew Luck          NaN    90.4
4          NaN   Drew Brees          NaN    95.6
5          NaN    Tom Brady          NaN    99.8
6  Andrew Luck          NaN          NaN   101.2
7   Drew Brees          NaN          NaN    94.6
8    Tom Brady          NaN          NaN   100.3

It looks okay but I don't want the NaN to be there.
Do any of you guys have any suggestions or fixes


F G

unread,
Dec 22, 2016, 9:31:47 AM12/22/16
to PyData
I dont know if I quite undertstood your question but ... 
dataframe.fillna() might be what you're looking for.


Cheers 

Pietro Battiston

unread,
Dec 22, 2016, 10:00:31 AM12/22/16
to pyd...@googlegroups.com
Il giorno gio, 22/12/2016 alle 06.22 -0800, F G ha scritto:
> I dont know if I quite undertstood your question but ... 
> dataframe.fillna() might be what you're looking for.
>

I suspect his problem lies in the call to concat() (that is, he wants a
9x2 rather than 9x4 DataFrame)... but it's hard to guess without seeing
the original DataFrames (in dfs).

Pietro
> -- 
> You received this message because you are subscribed to the Google
> Groups "PyData" group.
> To unsubscribe from this group and stop receiving emails from it,
> send an email to pydata+un...@googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.
Reply all
Reply to author
Forward
0 new messages