I have a csv file with multiple record types identified by the first character in the first field. How do I read this into a pandas dataframe filtering on records of type 'M'?
Asked
Active
Viewed 48 times
0
-
First create DataFrame by `df = pd.read_csv(file)` and then filter by dupe. – jezrael Jan 15 '18 at 14:06
-
Thanks, but cannot read the file in total as the file has varying numbers of fields. – Martin Jan 15 '18 at 14:23
-
1Welcome to StackOverflow. Please take the time to read this post on [how to provide a great pandas example](http://stackoverflow.com/questions/20109391/how-to-make-good-reproducible-pandas-examples) as well as how to provide a [minimal, complete, and verifiable example](http://stackoverflow.com/help/mcve) and revise your question accordingly. These tips on [how to ask a good question](http://stackoverflow.com/help/how-to-ask) may also be useful. – jezrael Jan 15 '18 at 14:24
-
Then get me know, I reopen question. – jezrael Jan 15 '18 at 14:24
-
My csv file is not regular, the different records can contain any number of fields, I don't know if these will fit into a dataframe. In the records below I only need those starting with 'M':- MA,1,2 MB,2,3 Z1,0,1,2,3,4 Z4,0,1,2 Z8,0,1,3,8,2,9 X2,4 MA,5 MB,6 Z1,0,1,5,3,4,7,9,25 Z4,0,1,4 – Martin Jan 15 '18 at 14:54