简体   繁体   中英

Retriving all the rows from a csv file and plotting

I need to retrieve the rows from a csv file generated from the function:

def your_func(row):
    return (row['x-momentum']**2+ row['y-momentum']**2 + row['z-momentum']**2)**0.5 / row['mass']

columns_to_keep = ['#time', 'x-momentum', 'y-momentum', 'z-momentum', 'mass']
dataframe = pd.read_csv("./flash.csv", usecols=columns_to_keep)
dataframe['mean_velocity'] = dataframe.apply(your_func, axis=1)

print dataframe

I got rows up until 29s then it skipped to the last few lines, also I need to plot this column 2 against 1

you can adjust pd.options.display.max_rows option, but it won't affect your plots, so your plots will contain all your data

demo:

In [25]: df = pd.DataFrame(np.random.randint(0,100,size=(10, 3)), columns=list('ABC'))

In [26]: df
Out[26]:
    A   B   C
0  93  76   5
1  33  70  12
2  50  52  26
3  88  98  85
4  90  93  92
5  66  10  58
6  82  43  39
7  17  20  91
8  47  90  33
9  44  30  26

In [27]: pd.options.display.max_rows = 4

Now it'll display 4 rows at most

In [36]: df
Out[36]:
     A   B   C
0   93  76   5
1   33  70  12
..  ..  ..  ..
8   47  90  33
9   44  30  26

[10 rows x 3 columns]

but it'll plot all your data

In [37]: df.plot.bar()
Out[37]: <matplotlib.axes._subplots.AxesSubplot at 0x49e2d68>

在此处输入图片说明

In [38]: pd.options.display.max_rows = 60

In [39]: df
Out[39]:
    A   B   C
0  93  76   5
1  33  70  12
2  50  52  26
3  88  98  85
4  90  93  92
5  66  10  58
6  82  43  39
7  17  20  91
8  47  90  33
9  44  30  26

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM